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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DheerajGupta
    New Member
    • Jun 2011
    • 3

    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..
  • Joseph Martell
    Recognized Expert New Member
    • Jan 2010
    • 198

    #2
    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.

    Comment

    • DheerajGupta
      New Member
      • Jun 2011
      • 3

      #3
      Thanks for time contribution.
      I have tried following code:
      Code:
      SystemEvents.SessionSwitch += new SessionSwitchEventHandler(SystemEvents_SessionSwitch);System.Events
      
      void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
      {
      	//Console.WriteLine("lock");
      	logee.WriteEntry("Inside SystemEvents_SessionSwitch ");
      	if (e.Reason == SessionSwitchReason.SessionLock)
      	{
      		isLockedTmp = true;
      	}
      	else if (e.Reason == SessionSwitchReason.SessionUnlock)
      	{
      		isLockedTmp = false;
      	}
      }


      the following code is worked finely in winxp but not worked in WS on win7
      Last edited by Plater; Jun 22 '11, 05:34 PM.

      Comment

      • Joseph Martell
        Recognized Expert New Member
        • Jan 2010
        • 198

        #4
        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?

        Comment

        • DheerajGupta
          New Member
          • Jun 2011
          • 3

          #5
          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 programmaticall y too.

          Comment

          • Joseph Martell
            Recognized Expert New Member
            • Jan 2010
            • 198

            #6
            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.

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

              #7
              Do you need to be run with access to the user's desktop (interactive) in order to catch those events from a service?

              Comment

              Working...