WTSSendmessage before stopping a service

て烟熏妆下的殇ゞ 提交于 2019-12-25 08:58: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:


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.



来源:https://stackoverflow.com/questions/10634450/wtssendmessage-before-stopping-a-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!