Process myProcess = new Process();
ProcessStartInfo remoteAdmin =
new ProcessStartInfo(Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\iisreset.exe /restart");
remoteAdmin.UserName = username;
remoteAdmin.Password = pwd;
remoteAdmin.Domain = domain;
myProcess.StartInfo = remoteAdmin;
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.Start(); --- ERROR HERE
Can not find the file specified.
But when I try to run iisreset on the local machine by cmd it’s working.
Unless I’m missing something,
(Environment.GetFolderPath(Environment.SpecialFolder.System)will get back the local machine (Where the code is running) special folder. So it’s expecting the fileC:\Windows\System\iisreset.exeto be located on your machine. The only method I could see to get around this, is to drop theC:\and instead add in the device’s name\\DeviceName\C$\and then the filepath. This is assuming the special folder system is located in the same place on your machine and the remote machine.The only other method, to get the remote machines system directory is to get it via WMI or via a reg entry reading.
So if using WMI:
Once done, you would then need to build the folder string yourself from that.