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é
 
Back
Top