Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your best (and by far safest) bet is to create a service that accepts the SERVICE_CONTROL_SESSIONCHANGE control.</p> <p>This will allow your service control handler to receive a control whenever a user logs on, logs off, locks the session, and various other options. Look for more info in a link blow.</p> <p>This is done by creating a service which has the SERVICE_ACCEPT_SESSIONCHANGE flag in the dwControlsAccepted, as following:</p> <pre><code>SERVICE_STATUS ss; ... ss.dwControlsAccepted |= SERVICE_ACCEPT_SESSIONCHANGE; </code></pre> <p>Followed by:</p> <pre><code>// This lets the service accept the session change ctrls // The service handle here is received by calling RegisterServiceCtrlHandler SetServiceStatus(hServiceHandle, &amp;ss); </code></pre> <p>This will allow windows to send SERVICE_CONTROL_SESSIONCHANGE controls to your HandlerEx function, which should look something like this:</p> <pre><code>DWORD WINAPI HandlerEx(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext) { switch (dwControl) { ...// Regular control handling case (SERVICE_CONTROL_SESSIONCHANGE): switch(dwEventType) { case(WTS_SESSION_LOGON): // Handle logon break; case(WTS_SESSION_LOCK): // Handle lock break; ... } break; ... } } </code></pre> <p>You can read up on all the different session change notifications you can receive from here: <a href="http://msdn.microsoft.com/en-us/library/aa383828%28v=VS.85%29.aspx" rel="noreferrer">WM_WTSSESSION_CHANGE</a>, all the notifications you'll need are in the wParam part of the description.</p> <p>Well, that's the gist of it anyway. You can read more info on the handlerex function here: <a href="http://msdn.microsoft.com/en-us/library/ms683241%28VS.85%29.aspx" rel="noreferrer">HandlerEx</a> and more information about services in general here: <a href="http://msdn.microsoft.com/en-us/library/ms685942%28v=VS.85%29.aspx" rel="noreferrer">Service Functions</a>. I suggest you read up on the ServiceMain function, RegisterServiceCtrlHandler function and, most importantly, read the examples posted on the MSDN pages. They're super helpful.</p> <p>Good luck!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload