Attempting to stop a Windows Service in a Web Application

From: Cash Foley (news_at_cashfoley.com)
Date: 07/29/03


Date: 29 Jul 2003 13:32:31 -0700


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);
}



Relevant Pages

  • Re: Modifying the NotifyIcon.Icon Property from Within A Service Application
    ... For a Windows Service I would recommend the Windows Event Log for exception ... Performance Counter and displayed the appropriate icon. ... resource file through the use of a sample Windows Forms application. ...
    (microsoft.public.dotnet.languages.vb)
  • WMI call fails when starting Windows service
    ... The code below is part of a .net Windows service. ... It intermittently fails ... To use WMI in a Windows service, do I need to specify any dependent services? ... // Other exception I've seen on this same line of code ...
    (microsoft.public.win32.programmer.wmi)
  • More on Connection Exception with Windows Service...!
    ... I am getting a connection exception when trying to access an SQL Server ... DOES NOT WORK: Windows SERVICE ... open database requested in login 'CRM'. ...
    (microsoft.public.dotnet.framework.adonet)
  • SoapException
    ... I have a Windows Service which serves an object for remoting. ... runs Ok until an exception is raised by this remotable object. ... port for the next 5 mins or so. ...
    (microsoft.public.dotnet.framework.remoting)
  • restarting windows service from my application
    ... windows service I created too. ... the exe linked to my service crashes (mostly runtime ... exception), and as a consequence my application can not work. ... Any help woulf be welcome! ...
    (microsoft.public.dotnet.languages.csharp)