windows service and working dir

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
I wrote a windows service and I've already installed with installutil tool. I have to write some output files but I can't use absolute path. So I need to set the program directory as working dir. How can I do?

PA
 
using System.IO;
using System.Reflection;

string dir = Assembly.GetExecutingAssembly().Location;
Directory.SetCurrentDirectory(dir.Substring(0, dir.LastIndexOf('\\')));

PA said:
Hi,
I wrote a windows service and I've already installed with installutil tool. I have to write some
output files but I can't use absolute path. So I need to set the program directory as working dir.
How can I do?
 
Just a small note here.
I will execute this code in the OnStart() method. Doing so will ensure that
the working directory is the location where your EXE is located and not the
System32 directory (which is the default for a Service).

José
 

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

Back
Top