CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2003
    Posts
    815

    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

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: killing a service

    Use StepService(). Take a look in MSDN at Stopping a Service in Platform SDK: DLLs, Processes, and Threads section.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    Jun 2004
    Location
    Chicago, United States
    Posts
    88

    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
  •  





Click Here to Expand Forum to Full Width

Featured