I am trying to restart iis remotely (Windows Servr 2012) from my local machine (Windows 7). The following command on the command line does not work to restart IIS;
iisreset servername /restart
but the command below works fine when I tried on the command line.
psexec iisreset \\servername /restart
Now the problem is that I'm trying to use the code below in C #,
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "\C psexec iisreset \\servername /restart";
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
process.StartInfo = startInfo;
process.Start();
// capture what is generated in command prompt
var output = process.StandardOutput.ReadToEnd();
If I give any other arguments in the above code, for example, "ipconfig", it gives me the expected result. But when I try to use psexec, it gives an empty output. But it works fine when trying on the command line.
I also tried using 'psexec.exe' in the file name and removing '\ C psexec' in the arguments. But still no luck.
Could you help me solve this problem?
Advance.