Groups | Blog | Home
all groups > dotnet myservices > april 2005 >

dotnet myservices : windows service - 2 simple (I hope) questions


Jan Waga
4/17/2005 12:00:00 AM
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

John Vottero
4/18/2005 12:00:00 AM
[quoted text, click to view]

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.


Jan Waga
4/19/2005 12:00:00 AM
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

Lee Gillie
4/26/2005 9:37:20 AM
[quoted text, click to view]

I believe the use of dependencies will control both start up and shut
Jan Waga
4/26/2005 10:06:40 AM
For society;)
There is no way you can control order in which services shut down (during
system shutdown).

Jan Waga
4/27/2005 12:00:00 AM
"Note that during service shutdown, the SCM does not take dependencies into
consideration. The SCM enumerates the list of running services and sends the
SERVICE_CONTROL_SHUTDOWN command. Therefore, a service may fail because
another service it depends on has already stopped."

http://msdn.microsoft.com/library/en-us/dllproc/base/service_control_handler_function.asp

AddThis Social Bookmark Button