Windows Service "Start In" Folder

  • Thread starter Thread starter Brian
  • Start date Start date
B

Brian

Is there a way to set the "start in" folder for a windows service?

I am running under the Local System account, and the start in folder
seems to be "c:\windows\system32". I use some relative filenames in my
application and would really like the start in folder to be something
more like "c:\apps\myservice".

I've looked at the ServiceInstaller class and ServiceProcessInstaller
class but they don't seem to have this option.

--Brian
 
Brian,

Instead of looking at the start in folder, why not look for the location
of the assembly using reflection, then use that for your relative file
paths?

Either that, or send the path to your directory in the parameters
textbox on the first page of the properties for the service.

Hope this helps.
 
Nicholas said:
Brian,

Instead of looking at the start in folder, why not look for the location
of the assembly using reflection, then use that for your relative file
paths?

Either that, or send the path to your directory in the parameters
textbox on the first page of the properties for the service.

Hope this helps.

Yes, that seems to be a good solution.

I'll use reflection once at the start of my service to get the
assembly's folder, and then use
System.IO.Directory.SetCurrentDirectory() so the rest of my application
can use relative paths.

--Brian
 
Back
Top