[ACCEPTED]-Getting full path for Windows Service-windows-services
Accepted answer
Try
System.Reflection.Assembly.GetEntryAssembly().Location
0
Try this:
AppDomain.CurrentDomain.BaseDirectory
(Just like here: How to find windows service exe path)
0
Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)
0
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;
0
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.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.