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