I am creating a small one page asp.net web forms application to reset IIS. This page contains a gridview with checkbox column to select the machines whose IIS reset is to be done. Then based on selection I will have to do the IIS reset of all selected machines.
Now the web application is hosted on Machine 1 on IIS and from this machine I will run the web application and select may be Machine 2, Machine 3 for IIS reset. I have written some code for IIS reset but it is giving me exception of Access Denied. Details are below.
try
{
using (ServiceController iisService = new ServiceController("W3SVC"))
{
TimeSpan timeout = TimeSpan.FromMilliseconds(10000);
iisService.MachineName = machineName;
if (iisService.Status == ServiceControllerStatus.Running)
{
iisService.Stop();
iisService.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
}
if (iisService.Status == ServiceControllerStatus.Stopped)
{
iisService.Start();
iisService.WaitForStatus(ServiceControllerStatus.Running, timeout);
}
}
}
After running the above code, I am receiving the below error:
cannot open w3svc service on computer 'machine name'
Also is there any other way I can do this, but I have to provide option for machine selection like a grid or something.