problem with relative paths inside windows service?

  • Thread starter Thread starter Julia
  • Start date Start date
J

Julia

Hi,

I have two application which 'evaluate'( New FileStream(path....) relative
path,
when evaluating the path inside a window service it always return something
like

C:\\WINNT\SYSTEM32\MyPath

While when evaluating it in a window application I get the correct path

both run from the same folder!!

Thanks.
 
Julia,
This is because a windows service does not run from the folder you have
placed. The current directory for a Windows service is the
C:\Windows\System32.
Try using exact paths if possible.
 
Julia,

If you want to get the path that the executing assembly is in, you
should get either the executing assembly (through a call to the static
GetExecutingAssembly method on the Assembly class) or the entry point (which
is your executable, I believe, obtained through a call to the static
GetEntryAssembly method on the Assembly class).

Once you have the Assembly instance, you can get the location through
the Location property on the assembly. From there, you can use the methods
on the Path class (in System.IO) to get the path of your files using a base
and a relative path.

Hope this helps.
 
Can I use the SetCurrentDirectory to set the running directory AFTER the
service was started
so all my relative paths function will work either in windows service or
window application?
 
It will not work out I am afraid once the Service has started. I will try
to research on this and find out. Thanks for giving me something to brood
overnight

Ranjan
 
Back
Top