none
How to get the status of system state(like whether its Locked, Unlocked) from windows service RRS feed

  • Question

  • Hi!
    I use C# and my application is windows service. I tried SystemEvents.SessionSwitch event from Microsoft.Win32 and it's work fine, but only in win application.Is there some method that allows to know the computer state from the service?
    Thanks.
    Tuesday, January 13, 2009 11:04 AM

Answers

  • There is no "computer state", the window station used by the user happens to be locked.  That doesn't say anything at all about others, like the one you get from RDP.  Services can no longer interact with the user in Vista and Windows 2008, best to avoid any dependency on work station state.  Run your app as a regular Windows .exe, started by the Run registry key or a Startup folder shortcut.


    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Monday, January 19, 2009 9:25 AM
    Tuesday, January 13, 2009 11:29 AM
    Moderator
  • Services that register a HandlerEx function gets notified of logon events (dwControl=SERVICE_CONTROL_SESSIONCHANGE, dwEventType=WTS_SESSION_LOGON/LOGOFF). Unfortunately that method is implemented inside the framework code and I don't think you get access to these notifications. It's easier to accomplish by writing a service in native code.
    Mattias, C# MVP
    • Marked as answer by Zhi-Xin Ye Monday, January 19, 2009 9:25 AM
    Tuesday, January 13, 2009 4:19 PM
    Moderator

All replies

  • There is no "computer state", the window station used by the user happens to be locked.  That doesn't say anything at all about others, like the one you get from RDP.  Services can no longer interact with the user in Vista and Windows 2008, best to avoid any dependency on work station state.  Run your app as a regular Windows .exe, started by the Run registry key or a Startup folder shortcut.


    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Monday, January 19, 2009 9:25 AM
    Tuesday, January 13, 2009 11:29 AM
    Moderator
  • Thanks!
    Than, how I can track lock/unlock event from Vista system. Maybe, I should subscribe to some WMI event. If so, which one?
    Tuesday, January 13, 2009 11:46 AM
  • Services that register a HandlerEx function gets notified of logon events (dwControl=SERVICE_CONTROL_SESSIONCHANGE, dwEventType=WTS_SESSION_LOGON/LOGOFF). Unfortunately that method is implemented inside the framework code and I don't think you get access to these notifications. It's easier to accomplish by writing a service in native code.
    Mattias, C# MVP
    • Marked as answer by Zhi-Xin Ye Monday, January 19, 2009 9:25 AM
    Tuesday, January 13, 2009 4:19 PM
    Moderator