the following is part for a c# code that I am working on:
string 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 processProcess*/
process = new Process
{
StartInfo = psi
}; /*Start the process*/
process.Start();
With this above the script run as expected.
The issue is if I move to 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 seem to me that there may be some restriction or filepath 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?