|
-
November 9th, 2004, 04:48 AM
#1
killing a service
Hi,
I have a service ,which I can start/stop threw administration tools/services
What i don't know is how do I stop/kill the sevice from instide
I mean If I notice a fatal error I want to:
1. kill the service
2. write a message to the event viewer (of course before killing the service)
Can anyone pls tell me how do I do the 2 things?
Thanks in advance
avi
P.S I don't know it matters but I'm using Win2000 OS
Thanks
-
November 9th, 2004, 06:54 AM
#2
Re: killing a service
Use StepService(). Take a look in MSDN at Stopping a Service in Platform SDK: DLLs, Processes, and Threads section.
-
November 9th, 2004, 10:20 AM
#3
Re: killing a service
I usually use ATL COM AppWizard to create a service application and call PostThreadMessge(dwThreadID,WM_QUIT,0,0) to stop the service from inside the service program.
The dwThreadID parameter is a main thread ID and can be taken from _Module.dwThreadID. To write a message to the event log I use CServiceModule::LogEvent function.
Code:
void CServiceModule::Run()
{
.....
// Init your service program here
MSG msg;
while (GetMessage(&msg, 0, 0, 0))
DispatchMessage(&msg);
//Clean up your service program here
LogEvent(_T("Service stopped"));
.....
}
A.M.
My Latest Articles:
CCustomBitmapButton - An owner-draw button and a frame for the caption bar, in one class.
CCustomTabCtrl - A clone of the Excel tab sheet control.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|