[ACCEPTED]-Getting full path for Windows Service-windows-services

Accepted answer
Score: 84

Try

System.Reflection.Assembly.GetEntryAssembly().Location

0

Score: 71

Try this:

AppDomain.CurrentDomain.BaseDirectory

(Just like here: How to find windows service exe path)

0

Score: 39
Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)

0

Score: 5

This works for our windows service:

//CommandLine without the first and last two characters
//Path.GetDirectory seems to have some difficulties with these (special chars maybe?)
string cmdLine = Environment.CommandLine.Remove(Environment.CommandLine.Length - 2, 2).Remove(0, 1);
string workDir = Path.GetDirectoryName(cmdLine);  

This 2 should give you the absolute path of the 1 executable.

Score: 5

Another version of the above:

string path = Assembly.GetExecutingAssembly().Location;
FileInfo fileInfo = new FileInfo(path);
string dir = fileInfo.DirectoryName;

0

Score: 3

Environment.CurrentDirectory returns current 4 directory where program is running. In case 3 of windows service, returns %WINDIR%/system32 2 path that is where executable will run rather 1 than where executable deployed.

More Related questions