gmailgmail
asked on
my program need to know when user switch to another windows user account (logoff->switch user)
My program needs to know when user switchs to another windows user account (logoff->switch user)
I want that when the user switch to another windows account my program will know about it.
I need it since my program take lots of resource and i want to suspend it when the user switches to different account.
IMPORTANT:
If he makes log-off then there is no problem since the program is shutting down by windows.
The problem is when he makes log-off -> switch users.
How can my program can get a signal from windows that windows is going to switch user account.
OR
If there was some api like IsCurrentAccountInLogOffMo de then i could use it from the first account
by using some timer.
Thanks
I want that when the user switch to another windows account my program will know about it.
I need it since my program take lots of resource and i want to suspend it when the user switches to different account.
IMPORTANT:
If he makes log-off then there is no problem since the program is shutting down by windows.
The problem is when he makes log-off -> switch users.
How can my program can get a signal from windows that windows is going to switch user account.
OR
If there was some api like IsCurrentAccountInLogOffMo
by using some timer.
Thanks
Another possibility is the use of a "Winlogon Notification Package Reference":
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/secauthn/security/winlogon_notification_package_reference.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/secauthn/security/winlogon_notification_package_reference.asp
ASKER
Idle_Mind thanks
Can i have some simple example in vb.
I only found vb.new example.
i have this:
FORM:
Option Explicit
Private Declare Function WTSRegisterSessionNotifica tion Lib "Wtsapi32" (ByVal hwnd As Long, ByVal THISSESS As Long) As Long
Private Declare Function WTSUnRegisterSessionNotifi cation 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()
Call WTSRegisterSessionNotifica tion(Me.hw nd, NOTIFY_FOR_ALL_SESSIONS)
End Sub
Module:
Private Const WM_WTSSESSION_CHANGE As Long = &H2B1
Private Const WTS_CONSOLE_CONNECT As Long = 1
Private Const WTS_CONSOLE_DISCONNECT As Long = 2
Private Const WTS_REMOTE_CONNECT As Long = 3
Private Const WTS_REMOTE_DISCONNECT As Long = 4
Private Const WTS_SESSION_LOGON As Long = 5
Private Const WTS_SESSION_LOGOFF As Long = 6
Private Const WTS_SESSION_LOCK As Long = 7
Private Const WTS_SESSION_UNLOCK As Long = 8
Private Const WTS_SESSION_REMOTE_CONTROL As Long = 9
Private Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
Private Const LANG_NEUTRAL = &H0
Public OldProc As Long
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
Debug.Print "A session was connected to the console session."
Case WTS_CONSOLE_DISCONNECT
Debug.Print "A session was disconnected from the console session."
Case WTS_REMOTE_CONNECT
Debug.Print "A session was connected to the remote session."
Case WTS_REMOTE_DISCONNECT
Debug.Print "A session was disconnected from the remote session."
Case WTS_SESSION_LOGON
Debug.Print "A user has logged on to the session."
Case WTS_SESSION_LOGOFF
Debug.Print "A user has logged off the session."
Case WTS_SESSION_LOCK
Debug.Print "A session has been locked."
Case WTS_SESSION_UNLOCK
Debug.Print "A session has been unlocked."
Case WTS_SESSION_REMOTE_CONTROL
Debug.Print "A session has changed its remote controlled status. To determine the status, call GetSystemMetrics and check the SM_REMOTECONTROL metric."
End Select
End Select
End Function
How can i make the event to go into WindowProc function?
Thanks
Can i have some simple example in vb.
I only found vb.new example.
i have this:
FORM:
Option Explicit
Private Declare Function WTSRegisterSessionNotifica
Private Declare Function WTSUnRegisterSessionNotifi
Private Const NOTIFY_FOR_ALL_SESSIONS As Long = 1
Private Const NOTIFY_FOR_THIS_SESSION As Long = 0
Private Sub Form_Load()
Call WTSRegisterSessionNotifica
End Sub
Module:
Private Const WM_WTSSESSION_CHANGE As Long = &H2B1
Private Const WTS_CONSOLE_CONNECT As Long = 1
Private Const WTS_CONSOLE_DISCONNECT As Long = 2
Private Const WTS_REMOTE_CONNECT As Long = 3
Private Const WTS_REMOTE_DISCONNECT As Long = 4
Private Const WTS_SESSION_LOGON As Long = 5
Private Const WTS_SESSION_LOGOFF As Long = 6
Private Const WTS_SESSION_LOCK As Long = 7
Private Const WTS_SESSION_UNLOCK As Long = 8
Private Const WTS_SESSION_REMOTE_CONTROL
Private Const FORMAT_MESSAGE_FROM_SYSTEM
Private Const LANG_NEUTRAL = &H0
Public OldProc As Long
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
Debug.Print "A session was connected to the console session."
Case WTS_CONSOLE_DISCONNECT
Debug.Print "A session was disconnected from the console session."
Case WTS_REMOTE_CONNECT
Debug.Print "A session was connected to the remote session."
Case WTS_REMOTE_DISCONNECT
Debug.Print "A session was disconnected from the remote session."
Case WTS_SESSION_LOGON
Debug.Print "A user has logged on to the session."
Case WTS_SESSION_LOGOFF
Debug.Print "A user has logged off the session."
Case WTS_SESSION_LOCK
Debug.Print "A session has been locked."
Case WTS_SESSION_UNLOCK
Debug.Print "A session has been unlocked."
Case WTS_SESSION_REMOTE_CONTROL
Debug.Print "A session has changed its remote controlled status. To determine the status, call GetSystemMetrics and check the SM_REMOTECONTROL metric."
End Select
End Select
End Function
How can i make the event to go into WindowProc function?
Thanks
ASKER
?? someone?
I don't know if you can override WndProc in VB6. You can, however, use a WH_CALLWNDPROC call to SetWindowsHookEx() to see messages before they're dispatched to the recipients.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks cookre .
But, i dont want to use hooks.
But, i dont want to use hooks.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This kind of thing is clumsy and not very extendible in VB6.
VB.Net does it easily and elegantly...
VB.Net does it easily and elegantly...
You need to use the WTSRegisterSessionNotifica
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/apcompat/apcompat/test_your_application_with_fast_user_switching.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/termserv/termserv/wtsregistersessionnotification.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/termserv/termserv/wm_wtssession_change.asp
~IM