Attempting to stop a Windows Service in a Web Application

C

Cash Foley

I'm attempting to stop a Windows Service from a Web Application. The
follow code generates a "Access is Denied" exception.

Can anyone help me with this?

Thanks in advance.

Cash

try
{
ServiceController[] services = ServiceController.GetServices();

foreach(ServiceController service in services)
{
if(service.ServiceName == "Service")
{
if(service.Status == ServiceControllerStatus.Stopped)
{
service.Start();
}
}
}
}
catch (Exception exc)
{
Response.Write("ERROR: " + exc.Message);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,436
Messages
2,571,696
Members
48,796
Latest member
Greg L.
Top