If anybody have requirement to restart Remote Machine IIS through code, then this is quite simple.
Scenario: If you are developing some assembly/dll, and need to deploy that dll in GAC. Each time you deploy that assembly in GAC, you must re-start IIS to see the changes.
Following code will make your life easy, because without going to server you can re-start IIS of that server.
Note:-To re-start remote machine IIS you must be an administrator of the remote computer. Either have your account added to the administrator local group of the remote computer or to the domain administrator global group.
static void Main(string args)
string serverName = string.Empty;
//Read input from Console
//First argument as ServerName
serverName = args;
//IISReset Process resides in WINDOWS\SYSTEM32 Folder
Process iisreset = Process.Start("iisreset.exe", @"C:\windows\system32");
//Pass Name of the server
iisreset.StartInfo.Arguments = serverName;
catch (Exception ex)
Console.WriteLine("ERROR:" + ex.Message);
Another way to do this is simple command:
Post a Comment