Reputation:
I do not know if this is even possible without breaking/crashing the process but is there a way to change the working directory of a System.Diagnostics.Process like you would when executing the cd (change directory) command from the cmd.exe command line interface?
Upvotes: 6
Views: 15127
Reputation: 945
As per MSDN, there is only one function which can change current folder, SetCurrentDirectory
and it has single string parameter, so the change is for current process only.
String oldWorkingDir = Directory.GetCurrentDirectory();
Directory.SetCurrentDirectory(myDirInfo.FullName);
operation();
Directory.SetCurrentDirectory(oldWorkingDir);
Upvotes: 6