Jango Posted June 18, 2009 Posted June 18, 2009 (edited) Hello,I found the following VB6 code:FORM CodeOption Explicit Private Declare Function WTSRegisterSessionNotification _ Lib "Wtsapi32" (ByVal hWnd As Long, _ ByVal THISSESS As Long) As Long Private Declare Function WTSUnRegisterSessionNotification _ Lib "Wtsapi32" (ByVal hWnd As Long) As Long Private Const NOTIFY_FOR_ALL_SESSIONS As Long = 1 Private Const NOTIFY_FOR_THIS_SESSION As Long = 0 Private Sub Form_Load() HookWindow Me.hWnd Call WTSRegisterSessionNotification(Me.hWnd, NOTIFY_FOR_ALL_SESSIONS) End SubMODULE Codeexpandcollapse popupOption Explicit Public Declare Function CallWindowProc _ Lib "user32" _ Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, _ ByVal hWnd As Long, _ ByVal msg As Long, _ ByVal wParam As Long, _ ByVal lParam As Long) As Long Public Declare Function SetWindowLong _ Lib "user32" _ Alias "SetWindowLongA" (ByVal hWnd As Long, _ ByVal nIndex As Long, _ ByVal dwNewLong As Long) As Long Public Const WM_WTSSESSION_CHANGE As Long = &H2B1 Public Const WTS_CONSOLE_CONNECT As Long = 1 Public Const WTS_CONSOLE_DISCONNECT As Long = 2 Public Const WTS_REMOTE_CONNECT As Long = 3 Public Const WTS_REMOTE_DISCONNECT As Long = 4 Public Const WTS_SESSION_LOGON As Long = 5 Public Const WTS_SESSION_LOGOFF As Long = 6 Public Const WTS_SESSION_LOCK As Long = 7 Public Const WTS_SESSION_UNLOCK As Long = 8 Public Const WTS_SESSION_REMOTE_CONTROL As Long = 9 Public Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000 Public Const LANG_NEUTRAL = &H0 Public Const GWL_WNDPROC As Long = (-4) Public Const WM_DESTROY = &H2 Public lPrevProc As Long Public Sub HookWindow(ByVal lHandle As Long) If lPrevProc = 0 Then lPrevProc = SetWindowLong(lHandle, GWL_WNDPROC, AddressOf WindowProc) Else Call SetWindowLong(lHandle, GWL_WNDPROC, lPrevProc) End If End Sub Public Function WindowProc(ByVal hWnd As Long, _ ByVal iMsg As Long, _ ByVal wParam As Long, _ ByVal lParam As Long) As Long Select Case iMsg Case WM_WTSSESSION_CHANGE Select Case wParam Case WTS_CONSOLE_CONNECT MsgBox "A session was connected to the console session at" & Now Case WTS_CONSOLE_DISCONNECT MsgBox "A session was disconnected from the console session at" & Now Case WTS_REMOTE_CONNECT MsgBox "A session was connected to the remote session at" & Now Case WTS_REMOTE_DISCONNECT MsgBox "A session was disconnected from the remote session at" & Now Case WTS_SESSION_LOGON MsgBox "A user has logged on to the session at" & Now Case WTS_SESSION_LOGOFF MsgBox "A user has logged off the session at" & Now Case WTS_SESSION_LOCK MsgBox "A session has been locked at" & Now Case WTS_SESSION_UNLOCK MsgBox "A session has been unlocked at" & Now Case WTS_SESSION_REMOTE_CONTROL MsgBox "A session has changed its remote controlled status. To determine the status, call GetSystemMetrics and check the SM_REMOTECONTROL metric at" & Now End Select Case WM_DESTROY HookWindow Form1.hWnd End Select WindowProc = CallWindowProc(lPrevProc, hWnd, iMsg, wParam, lParam) End FunctionI'm translating it in AutoIt but i really don't know how to translate this line: lPrevProc = SetWindowLong(lHandle, GWL_WNDPROC, AddressOf WindowProc)My problem is AdressOf WindowsProcCan someone help me ? Edited June 18, 2009 by Jango
ProgAndy Posted June 18, 2009 Posted June 18, 2009 (edited) i think, in AutoIt GUIRegisterMsg($WM_WTSSESSION_CHANGE, "WindowProc") should be enough hookig the windowproc is not required. Edited June 18, 2009 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes
Jango Posted June 18, 2009 Author Posted June 18, 2009 i think, in AutoIt GUIRegisterMsg($WM_WTSSESSION_CHANGE, "WindowProc") should be enough hookig the windowproc is not required.Thank you ProgAndy anyway I'm a little bit lost ... also to convert WindowProc function ...
ProgAndy Posted June 18, 2009 Posted June 18, 2009 (edited) It should be something like this: (still includes are missing, possibly some Constants are already declared in WindowsConstants) This was just some search'n'replace (Public Const -> Global Const $; &H -> 0x, ...) expandcollapse popupGlobal Const $WM_WTSSESSION_CHANGE = 0x2B1 Global Const $WTS_CONSOLE_CONNECT = 1 Global Const $WTS_CONSOLE_DISCONNECT = 2 Global Const $WTS_REMOTE_CONNECT = 3 Global Const $WTS_REMOTE_DISCONNECT = 4 Global Const $WTS_SESSION_LOGON = 5 Global Const $WTS_SESSION_LOGOFF = 6 Global Const $WTS_SESSION_LOCK = 7 Global Const $WTS_SESSION_UNLOCK = 8 Global Const $WTS_SESSION_REMOTE_CONTROL = 9 Global Const $FORMAT_MESSAGE_FROM_SYSTEM = 0x1000 Global Const $LANG_NEUTRAL = 0x0 Global Const $GWL_WNDPROC = (-4) Global Const $WM_DESTROY = 0x2 GUIRegisterMsg($WM_WTSSESSION_CHANGE, "MY_WM_WTSSESSION_CHANGE") Func MY_WM_WTSSESSION_CHANGE($hWnd, $uMsg, $wParam, $lParam) Switch $uMsg Case $WM_WTSSESSION_CHANGE Switch $wParam Case $WTS_CONSOLE_CONNECT MsgBox(0, "WM_WTSESSION_CHANGE", "A session was connected to the console session at " & _Now() ) Case $WTS_CONSOLE_DISCONNECT MsgBox(0, "WM_WTSESSION_CHANGE", "A session was disconnected from the console session at " & _Now() ) Case $WTS_REMOTE_CONNECT MsgBox(0, "WM_WTSESSION_CHANGE", "A session was connected to the remote session at " & _Now() ) Case $WTS_REMOTE_DISCONNECT MsgBox(0, "WM_WTSESSION_CHANGE", "A session was disconnected from the remote session at " & _Now() ) Case $WTS_SESSION_LOGON MsgBox(0, "WM_WTSESSION_CHANGE", "A user has logged on to the session at " & _Now() ) Case $WTS_SESSION_LOGOFF MsgBox(0, "WM_WTSESSION_CHANGE", "A user has logged off the session at " & _Now() ) Case $WTS_SESSION_LOCK MsgBox(0, "WM_WTSESSION_CHANGE", "A session has been locked at " & _Now() ) Case $WTS_SESSION_UNLOCK MsgBox(0, "WM_WTSESSION_CHANGE", "A session has been unlocked at " & _Now() ) Case $WTS_SESSION_REMOTE_CONTROL MsgBox(0, "WM_WTSESSION_CHANGE", "A session has changed its remote controlled status. To determine the status, call GetSystemMetrics and check the SM_REMOTECONTROL metric at " & _Now() ) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Edited June 18, 2009 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes
Jango Posted June 18, 2009 Author Posted June 18, 2009 Hello again i finnaly found this function that do the trick: Global Const $DESKTOP_SWITCHDESKTOP = 0x100 Func _CheckLocked() $hLockedDLL = DllOpen("user32.dll") $hDesktop = DllCall($hLockedDLL, "int", "OpenDesktop", "str", "Default", "int", 0, "int", 0, "int", $DESKTOP_SWITCHDESKTOP) $ret = DllCall($hLockedDLL, "int", "SwitchDesktop", "int", $hDesktop[0]) DllCall($hLockedDLL, "int", "CloseDesktop", "int", $hDesktop[0]) If $ret[0] = 0 Then $iLocked = 1 ElseIf $ret[0] = 1 Then $iLocked = 0 EndIf DllClose($hLockedDLL) If $iLocked Then Return 1 Else Return 0 EndIf EndFunc
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now