Author Message

PostPosted: Visual C# General, ServiceProcess Top

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

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

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.

Visual C#19  
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


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