"path to executable" of a windows service from a c# application

  • Thread starter jeanclaude.hernandez
  • Start date
J

jeanclaude.hernandez

Hello,

how can I get the "path to executable" of a windows service from a c#
application ?

I have tried the ServiceContoller class, ServiceBase class with no
results...

Thanks,
 
R

Robbe Morris [C# MVP]

Path.GetFileName(Assembly.GetExecutingAssembly().GetName().CodeBase))
 
J

jeanclaude.hernandez

Hi, thanks...but I can use it because it is not my service...I don't
have the code...I want to get the "path to executable" of a windows
service from ANOTHER c# application
 
T

The Other Nice Man

The information is stored in the registry key
HKLM\System\CurrentControlSet\Services\<%serviceName%>\ImagePath
contains the name of the executable including the full path.

Use the Microsoft.Win32.RegistryKey class to read this value which can
then split using GetDirectoryName to get the path.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top