Click here to Skip to main content
15,904,156 members
Home / Discussions / C#
   

C#

 
GeneralRe: Having trouble opening a registry key Pin
jochance13-Feb-24 9:30
jochance13-Feb-24 9:30 
GeneralRe: Having trouble opening a registry key Pin
OriginalGriff13-Feb-24 19:56
mveOriginalGriff13-Feb-24 19:56 
AnswerRe: Having trouble opening a registry key Pin
Richard Deeming8-Feb-24 22:47
mveRichard Deeming8-Feb-24 22:47 
AnswerRe: Having trouble opening a registry key Pin
Eddy Vluggen12-Feb-24 12:36
professionalEddy Vluggen12-Feb-24 12:36 
RantGlobal using? Pin
jschell8-Feb-24 4:42
jschell8-Feb-24 4:42 
GeneralRe: Global using? Pin
Richard Deeming8-Feb-24 5:19
mveRichard Deeming8-Feb-24 5:19 
GeneralRe: Global using? Pin
jochance13-Feb-24 9:34
jochance13-Feb-24 9:34 
QuestionHow to set up a Using..? Pin
glennPattonWork38-Feb-24 1:32
professionalglennPattonWork38-Feb-24 1:32 
AnswerRe: How to set up a Using..? Pin
Richard Andrew x648-Feb-24 1:38
professionalRichard Andrew x648-Feb-24 1:38 
GeneralRe: How to set up a Using..? Pin
glennPattonWork38-Feb-24 2:24
professionalglennPattonWork38-Feb-24 2:24 
GeneralRe: How to set up a Using..? Pin
Richard Andrew x648-Feb-24 2:33
professionalRichard Andrew x648-Feb-24 2:33 
GeneralRe: How to set up a Using..? Pin
glennPattonWork38-Feb-24 3:11
professionalglennPattonWork38-Feb-24 3:11 
AnswerRe: How to set up a Using..? Pin
Richard Deeming8-Feb-24 2:51
mveRichard Deeming8-Feb-24 2:51 
GeneralRe: How to set up a Using..? Pin
glennPattonWork38-Feb-24 3:10
professionalglennPattonWork38-Feb-24 3:10 
QuestionSystem.ServiceProcess.ServiceController.dll [SOLVED] Pin
Richard Andrew x643-Feb-24 2:38
professionalRichard Andrew x643-Feb-24 2:38 
AnswerRe: System.ServiceProcess.ServiceController.dll [SOLVED] Pin
jochance13-Feb-24 9:37
jochance13-Feb-24 9:37 
GeneralRe: System.ServiceProcess.ServiceController.dll [SOLVED] Pin
Richard Andrew x6413-Feb-24 12:16
professionalRichard Andrew x6413-Feb-24 12:16 
GeneralRe: System.ServiceProcess.ServiceController.dll [SOLVED] Pin
jochance13-Feb-24 12:46
jochance13-Feb-24 12:46 
Questionwhy cant I run powershell script from current directory Pin
Sherzaad132913251-Feb-24 22:04
Sherzaad132913251-Feb-24 22:04 
the following is part for a c# code that I am working on:

C#
// Specify the PowerShell script filename
    powerShellScriptFilename = @"C:\Users\sherz\OneDrive\Downloads\enableTouchScreen.ps1";

// Create process start info
ProcessStartInfo psi = new ProcessStartInfo
{
    FileName = "powershell.exe",
    Arguments = $"-NoProfile -ExecutionPolicy Bypass -Command \"{powerShellScriptFilename}\"",
    RedirectStandardInput = false,
    RedirectStandardOutput = false,
    RedirectStandardError = false,
    CreateNoWindow = true,
    UseShellExecute = true, //need to be set to true for 'Verb' to function
    Verb = "runas" //run application as Administrator
    //WorkingDirectory = Directory.GetCurrentDirectory()
};

// Create the process
Process process = new Process { StartInfo = psi };

// Start the process
process.Start();


With this above the script run as expected.

The issue is if I move the script to the 'currentDirectory' (ie the Project debug folder) the script is not executed.

I already tried updating 'powerShellScriptFilename' with the corresponding absolute path, script still worth execute.

As the code works if I chose a different location, it seems to me that there may be some restriction or filepath length issue.

My aim is to try and avoid hard coding the filepath to the script and I would like my program to pick its current directory to find the script and run it.

How can I test/do that if it is not possible to do that from the debug folder?

still quite new to C# but keen to learn! Smile | :)

modified 2-Feb-24 17:36pm.

AnswerRe: why cant I run powershell script from current directory Pin
Richard Deeming1-Feb-24 22:23
mveRichard Deeming1-Feb-24 22:23 
GeneralRe: why cant I run powershell script from current directory Pin
Sherzaad132913252-Feb-24 1:39
Sherzaad132913252-Feb-24 1:39 
AnswerRe: why cant I run powershell script from current directory Pin
jschell2-Feb-24 6:00
jschell2-Feb-24 6:00 
AnswerRe: why cant I run powershell script from current directory Pin
Sherzaad132913252-Feb-24 11:44
Sherzaad132913252-Feb-24 11:44 
GeneralRe: why cant I run powershell script from current directory Pin
Dave Kreskowiak5-Feb-24 7:05
mveDave Kreskowiak5-Feb-24 7:05 
GeneralRe: why cant I run powershell script from current directory Pin
trønderen7-Feb-24 4:49
trønderen7-Feb-24 4:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.