2012-08-28 5 views
2

하루 종일 RDP를 통해 내 PC (Windows XP Pro, 24/7 운영)에 연결합니다. RDP 연결시 일부 작업을 수행해야하는 백그라운드 프로세스가 있지만 RDP 연결 설정을 감지하는 방법을 찾지 못했습니다.RDP 연결 감지

새로운 프로세스가 생성되지 않아 WTSQuerySessionInformation이 도움이되지 않습니다 (동일한 영원한 Windows 세션에 연결).

아이디어가 있으십니까?

답변

1

대답은 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을 구현 한 것입니다