To run the IISADMIN service, you should have admin role in your
system.
The following code is a working code... i tried for Messanger since i
dont have "IISADMIN". I hope you will get ti done if you replace the
service name.
ServiceController controller = new ServiceController();
controller.ServiceName = "Messenger";
label1.Text = controller.Status.ToString();
if (controller.Status == ServiceControllerStatus.Running)
{
controller.Stop();
}
if (controller.Status == ServiceControllerStatus.Stopped)
{
controller.Start();
}
try this....OR try the below
ServiceController controller = new ServiceController("Messenger",
".");
if (controller.Status == ServiceControllerStatus.Running)
{
controller.Stop();
}
if (controller.Status == ServiceControllerStatus.Stopped)
{
controller.Start();
}
Vinki wrote:
Hello everyone,
I have this application that stops and starts IIS admin. When I try to
stop the service. I get an error "Cannot open IISADMIN service on computer
'.'.". I tried changing the machine name to my machine name then also it does
not work.
Below is the code
ServiceController controller = new ServiceController();
//controller.MachineName = "CS1239876";
controller.MachineName=".";
controller.ServiceName = "IISADMIN";
string status = controller.Status.ToString();
if(status == "Running)
controller.Stop();
Can anyone please help me with this.
Any help will be appreciated.