[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Traping the Switch User event in Windows XP

Posted on 2007-07-21
3
Medium Priority
?
835 Views
Last Modified: 2013-12-14
Can the Switch User Event in win xp  be trapped in a MFC application? My application must get notified when the user Switch's user [i.e. when the user switches in as well as when he switches off]

My application has to do some things when a user logs in or switches in. Similarly some things has to be done when the user logs off and/or switches off.

Is there way by which these events can be trapped?

Thanks in advance for your answer
0
Comment
Question by:Akhterrehan
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
Purple_Tidder earned 1500 total points
ID: 19538031
This may help a bit.  Someone was wanting to do just that with a VB6 app.

http://www.experts-exchange.com/Programming/Misc/Q_21438881.html
0
 
LVL 86

Expert Comment

by:jkr
ID: 19539078
You can register to receive a WM_WTSSESSION_CHANGE message when that occurs by calling 'WTSRegisterSessionNotification()' (http://msdn2.microsoft.com/en-us/library/aa383841.aspx), see http://support.microsoft.com/kb/310153 ("How To Write an Application That Supports Fast User Switching in Windows XP"). The scoop is to

WTSRegisterSessionNotification(AfxGetMainWnd()->GetSafeHwnd (), NOTIFY_FOR_THIS_SESSION);

class CMyMainWnd : public CWnd
{
//...

afx_msg LRESULT OnWM_WTSSESSION_CHANGE(WPARAM, LPARAM);

//...

BEGIN_MESSAGE_MAP( CMyMainWnd, CWnd )
    //{{AFX_MSG_MAP( CMyWnd
    ON_MESSAGE( WM_WTSSESSION_CHANGE, OnWM_WTSSESSION_CHANGE )
    // ... Possibly more entries to handle additional messages
    //}}AFX_MSG_MAP
END_MESSAGE_MAP( )

};


afx_msg LRESULT CMyMainWnd::OnWM_WTSSESSION_CHANGE(WPARAM wParam, LPARAM lParam)
{
   switch( wParam )
   {
      case WTS_CONSOLE_CONNECT:
         MessageBox(m_hWnd, TEXT("WTS_CONSOLE_CONNECT"),
                    TEXT("WM_WTSSESSION_CHANGE"), MB_OK );
         break;
      case WTS_CONSOLE_DISCONNECT:
         MessageBox(m_hWnd, TEXT("WTS_CONSOLE_DISCONNECT"),
                    TEXT("WM_WTSSESSION_CHANGE"), MB_OK );
         break;
      case WTS_SESSION_LOCK:
         MessageBox(m_hWnd, TEXT("WTS_SESSION_LOCK"),
                    TEXT("WM_WTSSESSION_CHANGE"), MB_OK );
         break;
      case WTS_SESSION_UNLOCK:
         MessageBox(m_hWnd, TEXT("WTS_SESSION_UNLOCK"),
                    TEXT("WM_WTSSESSION_CHANGE"), MB_OK );
         break;
   default:
      break;
   }

   return 0;
}
0
 
LVL 86

Expert Comment

by:jkr
ID: 19547009
???
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We have adopted the strategy to use Computers in Student Labs as the bulletin boards. The same target can be achieved by using a Login Notice feature in Group policy but it’s not as attractive as graphical wallpapers with message which grabs the att…
It is only natural that we all want our PCs to be in good working order, improved system performance, so that is exactly how programs are advertised to entice. They say things like:            •      PC crashes? Get registry cleaner to repair it!    …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month19 days, 2 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question