ServiceStartMode

  • Thread starter Thread starter Jerry
  • Start date Start date
J

Jerry

I'm trying to find a name space/class that I can use in ASP.NET to access an
exiting windows service's startup type setting.
I've found the System.ServiceProcess.ServiceInstaller has an enumeration of
ServiceStartMode but that is used to install a new service. My service has
already been installed and I'm just trying to determine if the start mode
has been disabled.

I know that you can use System.ServiceProcess.ServiceController to query the
service but it doesn't have any property that can be used to access the
start mode..

TIA

Jerry
 
Hi Jerry -

The System.Management namespace allows you to query all kinds of system data, including services and their start
mode.

Here's a simple console app that demonstrates the basic approach. It assumes the service short name as input - for
example, input "EventLog" to get the information about the event log service.

using System;
using System.Management;

public class Sample
{

public static void Main(string[] args)
{

if (args.Length > 0)
{
String myServiceName = args[0];

try
{

// Query WMI for additional information about this service.

ManagementObject wmiService;
wmiService = new ManagementObject("Win32_Service.Name='" + myServiceName + "'");
wmiService.Get();

Console.WriteLine("Service Name = {0}", myServiceName);
Console.WriteLine("Start name:\t{0}", wmiService["StartName"]);

Console.WriteLine("Start mode:\t{0}", wmiService["StartMode"]);
Console.WriteLine("Service path:\t{0}", wmiService["PathName"]);
Console.WriteLine("Description:\t{0}", wmiService["Description"]);
}
catch (System.Management.ManagementException)
{
Console.WriteLine("Could not query for Win32_Service.Name = {0}", myServiceName);
Console.WriteLine("The service might not be installed on this computer.");
}
}
else
{

Console.WriteLine("First argument = service name");
}

}
}

Hope this helps!
Doyle

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

--------------------
 
Thanks..

I was using the serviceprocess namespace to determine if the service is
running, stopped, paused etc.. and to restart it, stop it etc..
Why not provide the startup type in the serviceprocess ? Why use management
namespace?




"Doyle Cronk [MSFT]" said:
Hi Jerry -

The System.Management namespace allows you to query all kinds of system
data, including services and their start
mode.

Here's a simple console app that demonstrates the basic approach. It
assumes the service short name as input - for
example, input "EventLog" to get the information about the event log service.

using System;
using System.Management;

public class Sample
{

public static void Main(string[] args)
{

if (args.Length > 0)
{
String myServiceName = args[0];

try
{

// Query WMI for additional information about this service.

ManagementObject wmiService;
wmiService = new ManagementObject("Win32_Service.Name='" + myServiceName + "'");
wmiService.Get();

Console.WriteLine("Service Name = {0}", myServiceName);
Console.WriteLine("Start name:\t{0}", wmiService["StartName"]);

Console.WriteLine("Start mode:\t{0}", wmiService["StartMode"]);
Console.WriteLine("Service path:\t{0}", wmiService["PathName"]);
Console.WriteLine("Description:\t{0}",
wmiService["Description"]);
}
catch (System.Management.ManagementException)
{
Console.WriteLine("Could not query for Win32_Service.Name = {0}", myServiceName);
Console.WriteLine("The service might not be installed on this computer.");
}
}
else
{

Console.WriteLine("First argument = service name");
}

}
}

Hope this helps!
Doyle

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm
--------------------
From: "Jerry" <[email protected]>
Subject: ServiceStartMode
Date: Tue, 26 Aug 2003 09:57:13 -0400
Lines: 16
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework
NNTP-Posting-Host: pool-138-88-22-73.res.east.verizon.net 138.88.22.73
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework:52251
X-Tomcat-NG: microsoft.public.dotnet.framework

I'm trying to find a name space/class that I can use in ASP.NET to access an
exiting windows service's startup type setting.
I've found the System.ServiceProcess.ServiceInstaller has an enumeration of
ServiceStartMode but that is used to install a new service. My service has
already been installed and I'm just trying to determine if the start mode
has been disabled.

I know that you can use System.ServiceProcess.ServiceController to query the
service but it doesn't have any property that can be used to access the
start mode..

TIA

Jerry
 
Back
Top