Windows Service "Start In" Folder

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
B

Brian

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top