This is a Windows service example based on arcker’s UDF. This service captures the SERVICE_CONTROL_SESSIONCHANGE event as described in HandlerEx documentation. This event triggers a WM_WTSSESSION_CHANGE message whose handler function accepts four parameters. The handler function is none but the HandlerEx callback function already registered by a call to RegisterServiceCtrlHandlerEx. The third parameter of HandlerEx function is of our interest as; the system sends one or more of the nine messages depending upon the session change event that has taken place, viz. WTS_CONSOLE_CONNECT, WTS_CONSOLE_DISCONNECT, WTS_REMOTE_CONNECT, WTS_REMOTE_DISCONNECT, WTS_SESSION_LOGON, WTS_SESSION_LOGOFF, WTS_SESSION_LOCK, WTS_SESSION_UNLOCK & WTS_SESSION_REMOTE_CONTROL. The second parameter of HandlerEx is of little less importance. It contains a pointer to WTSSESSION_NOTIFICATION structure which, in turn, embeds the session ID of the user who has caused the session change event to take place.
- Download : http://www.autoitscript.com/forum/topic/80201-service-udf-v2-run-your-exe-as-service/#entry577218 (Scroll until the entry titled “Examples / Session Change / v1 (lock, logon, etc) By HolmesShelock”)
- Discussion : http://www.autoitscript.com/forum/topic/80201-service-udf-v2-run-your-exe-as-service/