2vision2
2vision2

Reputation: 5023

WTSSendmessage before stopping a service

Am trying to display a message box once the user tries to stop a service.

For this I used WTSSendmessage API... And I called the function once the SERVICE_CONTROL_STOP event occurs..

Am I right in the above step?? Because am not getting a message box once the user trie to stop the service..

Please guide me...

Below is my code snippet::

case SERVICE_CONTROL_STOP:
    WTSSendMessage = (fptr1)GetProcAddress(hinstLib, "WTSSendMessage");
    BOOL ret = WTSSendMessage(WTS_CURRENT_SERVER_HANDLE, dwSession, lpszTitle, 12 ,lpszText, 7 ,MB_YESNO|MB_ICONINFORMATION, 0, &res, TRUE);

    ServiceStatus.dwCurrentState = SERVICE_STOP_PENDING;
    SetServiceStatus( serviceStatusHandle, &serviceStatus );
    SetEvent( stopServiceEvent );
    return;

Upvotes: 0

Views: 3170

Answers (1)

David Heffernan
David Heffernan

Reputation: 612993

Use WTSGetActiveConsoleSessionId() as described in the MSDN article I showed you in your earlier question. That article includes all the code you need.

I also urge you to include error checking for your API calls. Diagnosing errors without that help is harder than it needs to be.

Upvotes: 1

Related Questions