How do I get the path to a Windows Service executable

  • Thread starter Thread starter Bill Fuller
  • Start date Start date
B

Bill Fuller

I tried reading a file into an application running as a Windows Service,
however it is not returning the correct location for the running executable.
How do I determine the full path for this?
 
Hello

I think u can get the executable path using
AppDomain.CurrentDomain.BaseDirectory



Regards

Shrihari Devji
 
Hello,

AppDomain.CurrentDomain.BaseDirectory does not guaranty to return
assembly's path (although it will do it most of the cases).
BaseDirectory is used by the CRL to probe for assemblies and can be
configured when the AppDomain is created.

You can use the following code to get the path:


System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)

Sebastian
 

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

Back
Top