[ACCEPTED]-Getting full path for Windows Service-windows-services
(Just like here: How to find windows service exe path)
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.
Another version of the above:
string path = Assembly.GetExecutingAssembly().Location; FileInfo fileInfo = new FileInfo(path); string dir = fileInfo.DirectoryName;
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