Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

I want to iisreset a remote machine from my local using c#.
iisreset <servername> /start is working from command prompt but when i am using the same script from c# code it is not working.
Here is the code attached:
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
//startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/c iisreset <servername> /start";
process.StartInfo = startInfo;
process.Start();

Anyhelp would be really appreciated.

What I have tried:

I have tried modifying startinfo.arguements to:
startInfo.Arguments = "iisreset <servername> /start";
Posted
Updated 29-Nov-17 16:54pm

1 solution

I just created a test app & it works fine using the below code;
C#
Process proc = new Process();
ProcessStartInfo sinfo = new ProcessStartInfo();
sinfo.FileName = "cmd.exe";
// note: the double slashes are to escape the \ character
sinfo.Arguments = "/c c:\\windows\\system32\\iisreset.exe myservername /start";
proc.StartInfo = sinfo;
proc.Start();

Things that may stop it working;
a) IISRESET is not installed on the local machine
b) You need to include the full path - the command prompt that you open may not include iisreset it it's path
c) The command prompt is not a local admin on the remote machine - an elevated command prompt is required on the local machine

Short answer is, you need to debug & test. If you get rid of your arguments & just open the command prompt, can you actually run the command?

Kind Regards
 
Share this answer
 
Comments
Member 14598472 26-Sep-19 7:08am    
What Is Server name I Write
an0ther1 1-Oct-19 21:45pm    
The name of the machine that IIS is running on

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900