Reputation: 506
When in my program I try to launch particular exe-file "nvidia-smi.exe" (NVIDIA System Management Interface program), I receive the error "System.ComponentModel.Win32Exception. The system cannot find the file specified"
string directoryPath = "C:\\";
string fileName = "nvidia-smi.exe";
Console.WriteLine(System.IO.File.Exists(directoryPath + fileName)); //true
proc.StartInfo.WorkingDirectory = directoryPath;
proc.StartInfo.FileName = fileName;
proc.Start(); //Error. The system cannot find the file specified
But at the same time I can :
1) Launch the other files from the same directory (exe, bat etc)
2) Successfully to execute the file I needed "nvidia-smi.exe" if relocate it to my project's directory and do not use the property "proc.StartInfo.WorkingDirectory".
-----------------The answer is (Thanks for help!)------------------
you need this :
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.WorkingDirectory = "C:\\";
proc.StartInfo.FileName = "nvidia-smi.exe";
Or this :
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.FileName = "C:\\nvidia-smi.exe";
Upvotes: 0
Views: 99
Reputation: 9704
If you set proc.StartInfo.UseShellExecute
to true, the behavior of WorkingDirectory
will be as you expect it to be. Otherwise, you will have to either specify the absolute path for the FileName
, or make sure your executable is in your environment path.
Relevant documentation:
Upvotes: 2