WTSSendmessage before stopping a service

2019-08-17 00:14发布

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;

1条回答
forever°为你锁心
2楼-- · 2019-08-17 00:37

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.

查看更多
登录 后发表回答