ServiceProcess  
Author Message
Eyalrev





PostPosted: Visual C# General, ServiceProcess Top

Hi,
i'm trying to obtain a list of services on my computer as follow:
string s = string.Empty;
ServiceController[] services;
services = ServiceController.GetServices();

listBox1.BeginUpdate();
foreach (System.ServiceProcess.ServiceController ctrl in services)
{
System.ServiceProcess.ServiceControllerStatus stat = ctrl.Status;
System.ServiceProcess.ServiceType st = ctrl.ServiceType;

s = ctrl.DisplayName;
s += " " + ctrl.ServiceName;
s+= " " + stat.ToString();
s += " " + st.ToString();
listBox1.Items.Add(s );
}
listBox1.EndUpdate();


but i don't know how to obtain the startup type of specific service.
for example i want to know if some service has a state of manual,automatic.
i know how to set service to this mode but i dont know how to READ it.

Please Help.
Thanks



Visual C#17  
 
 
James Curran





PostPosted: Visual C# General, ServiceProcess Top

You're right....There doesn't seem to be a simple way to read it. I think this is because it's startup type isn't really a property of the service, but instead of booting.

Anyway, a klugy by functional method would be to check the registry under

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\(ctrl.ServiceName)\Start

(2 = automatic, 3 = manual, 4 = disabled)