Why is this
ProcessStartInfo myProcess = new ProcessStartInfo(path);
myProcess.UserName = username;
myProcess.Password = MakeSecureString(password);
myProcess.UseShellExecute = false;
Process.Start(myProcess);
working, but
ProcessStartInfo myProcess = new ProcessStartInfo();
myProcess.FileName = Path.GetFileName(path);
myProcess.WorkingDirectory = Path.GetDirectoryName(path);
myProcess.UserName = username;
myProcess.Password = MakeSecureString(password);
myProcess.UseShellExecute = false;
Process.Start(myProcess);
is not.
I wanted to use the second one because of this question: https://stackoverflow.com/a/2621943/1306186
I am constantly getting a file not found exception… Any ideas?
Edit:
Path is for example @"C:\Users\User\Desktop\ConsoleApplication2.exe"
This bit is wrong
this should be
Pass in
C:\SomeDir\SomeApp.exeand the code you have will set the filename toSomeApp.exe, which it can’t find. Count yourself lucky, there are circumstances where it could have (e.g. your app and the app you want to run being in the same folder), and then you would have possibly got a funny when deploying.