windows service - 2 simple (I hope) questions

  • Thread starter Thread starter Jan Waga
  • Start date Start date
J

Jan Waga

Hello,

I've written and installed windows service in C#. I have two questions:

1)

File.Open("lock", FileMode.OpenOrCreate, FileAccess.Read, FileShare.None)
does not create the file even if it doesn't exist.

Also:
Directory.Exists(ConfigDirectoryName)
returns always true (even if the directory doesn't exists)

I am sure paths are OK, my service runs under LocalSystem account which has
necessary (all, in fact) rights to the application directory. The service
CAN create files in the directory (I've checked).

The same code run from console application works fine.

What may be wrong? Why my service tells me files and directories exist, when
they don't? :)

2)

Is there some way to control the order in which services stop when the
system shuts down? My service depends on WMI, I have specified this in the
code. But when OnShutdown() code is running, I'm positively sure WMI is no
longer working.

I'd appreciate any help,
Jan
 
Jan Waga said:
Hello,

I've written and installed windows service in C#. I have two questions:

1)

File.Open("lock", FileMode.OpenOrCreate, FileAccess.Read, FileShare.None)
does not create the file even if it doesn't exist.

Also:
Directory.Exists(ConfigDirectoryName)
returns always true (even if the directory doesn't exists)

I am sure paths are OK, my service runs under LocalSystem account which
has
necessary (all, in fact) rights to the application directory. The service
CAN create files in the directory (I've checked).

The same code run from console application works fine.

What may be wrong? Why my service tells me files and directories exist,
when
they don't? :)

Are you sure that you're looking in the correct directory? When a service
starts, it's default directory is %SystemRoot%\System32. If you look there,
I think that you'll find your "lock" file and the directory that
ConfigDirectoryName points at.
 
You're right of course. I was sure that default directory would be
application directory. I didn't check it.
I'm still working on the second matter, though...:)

Thank you for your help.
Jan
 
For society;)
There is no way you can control order in which services shut down (during
system shutdown).
 
Back
Top