469,352 Members | 2,140 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

Windows service not able to capture Login/Lock/Unlock in win7

Windows service not able to capture Login/Lock/Unlock in Win7.
if any one knows the solution or any idea or approach, please help me out.
waiting for all of your positive response.

Thanks in Advance..
Jun 13 '11 #1
6 8514
Joseph Martell
198 Expert 128KB
Any more information? What have you tried so far? Your question makes it sound like you have tried one method and have received unsuccessful results. Is this the case or are you looking for a place to start?

If you are looking for a standard solution, you should investigate the Microsoft.Win32.SystemEvents class.

If you are looking for help with a non-functioning solution, we need more information from you about the solution that you have already tried. Post what you have done and in what way it is specifically failing. Exceptions are a great place to start.
Jun 14 '11 #2
Thanks for time contribution.
I have tried following code:
Expand|Select|Wrap|Line Numbers
  1. SystemEvents.SessionSwitch += new SessionSwitchEventHandler(SystemEvents_SessionSwitch);System.Events
  2.  
  3. void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
  4. {
  5.     //Console.WriteLine("lock");
  6.     logee.WriteEntry("Inside SystemEvents_SessionSwitch ");
  7.     if (e.Reason == SessionSwitchReason.SessionLock)
  8.     {
  9.         isLockedTmp = true;
  10.     }
  11.     else if (e.Reason == SessionSwitchReason.SessionUnlock)
  12.     {
  13.         isLockedTmp = false;
  14.     }
  15. }
  16.  


the following code is worked finely in winxp but not worked in WS on win7
Jun 14 '11 #3
Joseph Martell
198 Expert 128KB
Interesting. The MSDN documentation says that that same method should work with Windows 7. Unfortunately, I do not have a Windows 7 machine so my testing ability is kind of stunted.

Have you checked the error log to see if there are any entries there? Are you getting any exceptions or anything?
Jun 15 '11 #4
Thanks Joseph for your involvement, actually there is no exception rather then its not reaching the SessionSwitch event. even i have made my machine lock\unlock manually or lock programmatically too.
Jun 15 '11 #5
Joseph Martell
198 Expert 128KB
I had a similar problem with a windows service. It worked on every Windows XP Pro SP3 machine that I could find, but it would not work on Windows XP embedded. My theory was that I needed to add a dependency that I didn't know about.

I would suggest checking your dependencies. In windows xp you have to make sure your service starts after "System Event Notification" (SENS) and "Event Log" (Eventlog), I believe. I assume there are complimentary services in Windows 7 that must be listed as dependencies.

Also, have you tried stopping and restarting your service on the Windows 7 machine? Even though my service would not detect log on/ log off events on the Windows Embedded machine, it would detect the events if I stopped and restarted the service. I couldn't figure out why, but it could at least tell you if it is your code or the way that Windows 7 is handling your service that is the problem.
Jun 17 '11 #6
Plater
7,872 Expert 4TB
Do you need to be run with access to the user's desktop (interactive) in order to catch those events from a service?
Jun 22 '11 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by =?Utf-8?B?Y2FzaGRlc2ttYWM=?= | last post: by
reply views Thread by =?Utf-8?B?c3VqaXRo?= | last post: by
4 posts views Thread by =?Utf-8?B?Um9iZXJ0?= | last post: by
4 posts views Thread by pbd22 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.