Search code examples
c#powershellcommand

C# PowerShell Start-Command FilePath does not find my C driver


I am writing C# application which is made for execute some file in some directories but when I try type my dir path to "Start-Process" with "AddParameter" command it gives this error ;

'Cannot find drive. A drive with the name 'C' does not exist.' DriveNotFoundException: Cannot find drive. A drive with the name 'C' does not exist.

Set-Location command can find the 'C:' path, the below command doesn't give any error ,

ps.AddCommand("Set-Location").AddParameter("Path", "C:\\Users\\User1\\Documents\\exectuteDir\\").Invoke();

but this one throws a error,

ps.AddCommand("Start-Process").AddParameter("NoNewWindow").AddParameter("FilePath", "C:\\Users\\User1\\Documents\\exectuteDir\\some.exe")

Thanks in advance

I tried with PS shell in order to correct my path dir and it is normal moreover I did it with "Set-Location" command and there was no problem but to get there but after "Set-Location" "Start-Process" gives same error again


Solution

  • I used 'Process' library to put command on command-line.

    Using the PS hard for me and I think when PS called from application it starts on different OS layer therefore you can't execute whatever you want.

    Thanks