대답은 wtsapi32.dll의 WTSRegisterSessionNotification()입니다. WParam이 WTS_REMOTE_CONNECT, WTS_REMOTE_DISCONNECT 일 수있는 WM_WTSSESSION_CHANGE 알림을 수신하도록 등록합니다. 그건 그렇습니다.
#include <GUIConstantsEx.au3>
#include <Date.au3>
#include <WindowsConstants.au3>
Global Const $hWTSAPI32 = DllOpen("wtsapi32.dll")
Global $i = 0, $tTime
_Main()
Func _Main()
Local $hGUI
; Create GUI
$hGUI = GUICreate("Session change detection", 600, 400)
;~ GUISetState() ; show the window
DllCall($hWTSAPI32, "int", "WTSRegisterSessionNotification", "hwnd", $hGUI, "dword", 1) ; NOTIFY_FOR_ALL_SESSIONS
If @error Then
MsgBox(0,"", "Error calling WTSRegisterSessionNotification()")
Exit
EndIf
GUIRegisterMsg(0x2B1, "WTSSESSION_CHANGE") ; WM_WTSSESSION_CHANGE <=====================
; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc ;==>_Main
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func WTSSESSION_CHANGE($hWndGUI, $MsgID, $WParam, $LParam)
; WTS_REMOTE_CONNECT = 0x3, WTS_REMOTE_DISCONNECT = 0x4
; WTS_SESSION_UNLOCK = 0x8, WTS_SESSION_LOGON = 0x5
If $WParam = 3 Then
$tTime = _Date_Time_GetSystemTime()
MsgBox(0, "Caught a notification", "Remote session connected at " & _Date_Time_SystemTimeToDateTimeStr($tTime))
Exit
EndIf
EndFunc
: 여기
는 간단한 AutoIt을 구현 한 것입니다