get list of services on a pc

  • Thread starter Thread starter Yankee Imperialist Dog
  • Start date Start date
Y

Yankee Imperialist Dog

is there a way to get a list of all services that exist on a pc/server?

knowing the name it's easy to get a reference
ServiceController sc = new ServiceController("A Service Installed Here");
but i'd like to get a list of all services.

Thanks
 
Figured it out

using Microsoft.Win32;
----
----
--

RegistryKey rk = Registry.LocalMachine;
rk = rk.OpenSubKey(@"SYSTEM\CurrentControlSet\Services");
foreach (string keyName in rk.GetSubKeyNames())
{
Console.WriteLine(keyName);
}

thanks
KES
 
YankeeImperialistDog said:
Figured it out
rk = rk.OpenSubKey(@"SYSTEM\CurrentControlSet\Services");
foreach (string keyName in rk.GetSubKeyNames())

Surely there is a better way than that. What happens if they change the
location of this information in the registry or decide to add extra keys
that don't represent a service, or create services somewhere else in the
registry. I think dot net has built in support for this. If not, use
interop.

Michael
 
Yankee said:
is there a way to get a list of all services that exist on a pc/server?

knowing the name it's easy to get a reference
ServiceController sc = new ServiceController("A Service Installed Here");
but i'd like to get a list of all services.
ServiceController.GetServices().
 
this does answer the question above. And yes this is the better way.
Your help and commets are appreciated.
 
Back
Top