How do I find the install directory of a Windows Service, using C#? -


I'm pretty sure that a Windows service is in C: \ winnt (or similar) as its working directory InstallUtil when running.program file. Can I in any way access, or otherwise capture (at the established time), the service that was originally installed from the directory? At the moment, I'm manually entering the app.exe.config file, but it is very manual and looks like a hack.

Is there a programmatic way, either on time or at the time of installation, how was the service established?

You can use reflection to get the place of execution assembly. Here is a simple routine that sets the working directory on the place of execution assembly using reflection:

  string path = system. Reflection.Assembly.GetExecutingAssembly () place; Path = System.IO.Path.GetDirectoryName (path); Directory.SetCurrentDirectory (Path);  

Comments