1

Is there any way to get the files associated with a windows service? Local and remote machine. In case of IIS i use the config file to get list of IIS services and their absolute path on the machine. Need to do this via code.

Thanks

EDIT: To make the question clear, i need to get the installation path of the service.

Variant
  • 17,279
  • 4
  • 40
  • 65
Aadi Droid
  • 1,689
  • 4
  • 22
  • 46

1 Answers1

0

System.Diagnostics has functionality to query running processes:

Process[] processlist = Process.GetProcesses();

foreach(Process theprocess in processlist){
    Console.WriteLine(“Process: {0} ID: {1} File {2}”, 
        theprocess.ProcessName, 
        theprocess.Id, 
        theprocess.MainModule.FileName);
}

If you want installed services rather then running processes you can use:

ServiceController.GetServices()

from System.ServiceProcess

you can get the file paths using the methodology described here: how to get phyiscal path of windows service using .net?

Community
  • 1
  • 1
Variant
  • 17,279
  • 4
  • 40
  • 65
  • i was just going to update here that i achieved it using WMI ! Thanks for the link. I'll accept your answer. – Aadi Droid Jul 11 '11 at 08:49