I have a windows service and I need to create directory to store some info. The directory path must be relative to the windows service exe file. How can get this exe file pa
To get path for service you can use Management object. ref: https://msdn.microsoft.com/en-us/library/system.management.managementobject(v=vs.110).aspx http://dotnetstep.blogspot.com/2009/06/get-windowservice-executable-path-in.html
using System.Management;
string ServiceName = "YourServiceName";
using (ManagementObject wmiService = new ManagementObject("Win32_Service.Name='"+ ServiceName +"'"))
{
wmiService.Get();
string currentserviceExePath = wmiService["PathName"].ToString();
Console.WriteLine(wmiService["PathName"].ToString());
}