Moment when all interactive user accounts have been logged out
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: Moment when all interactive user accounts have been logged out

  1. #1
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    831

    Moment when all interactive user accounts have been logged out

    I'm writing a Windows service using WinAPIs and C++. One of the options is that I need to send the system into sleep after all users are logged out. The log-out command is started from the UI (which can notify my service), the problem is knowing how long it takes for all user accounts to be completely logged out before putting the system to sleep.

    I first thought to introduce an artificial delay from the moment when the log-out command is issued and before entering the sleep mode, but in a situation when some user account was configured with a roaming profile, the log-out process may well exceed my delay.

    So any suggestions how to know if all user accounts are logged out "for sure"?

  2. #2
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,854

    Re: Moment when all interactive user accounts have been logged out

    This may be of help. It provides info about all users currently logged on.

    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,485

    Re: Moment when all interactive user accounts have been logged out

    Quote Originally Posted by 2kaud View Post
    This may be of help. It provides info about all users currently logged on.

    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
    If this api is used, be sure to read the remarks section with regard to services impersonating users.

  4. #4
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    831

    Re: Moment when all interactive user accounts have been logged out

    @2kaud: Thanks for the link.

    @Arjay: Thank you for the heads-up. So is there a way to see if the entry returned is from a service doing the impersonation or if it is from an actual interactive user?

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,485

    Re: Moment when all interactive user accounts have been logged out

    Quote Originally Posted by dc_2000 View Post
    @Arjay: Thank you for the heads-up. So is there a way to see if the entry returned is from a service doing the impersonation or if it is from an actual interactive user?
    I don't know offhand. Try info level 1 with a service that is started under a user account and compare it with a service started under a local service account. You might have to use other apis to walk the running service processes to retrieve the user they are running under.

  6. #6
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,854

    Re: Moment when all interactive user accounts have been logged out

    EnumServicesStatusEx()
    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
    provides some info about all the services installed on the system. Unfortunately, it doesn't provide the name of the account under which the services are running. To get this info you use
    QueryServiceConfig() for a specified service
    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
    and lpServiceStartName in the QUERY_SERVICE_CONFIG structure contains the service logon account name.
    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  7. #7
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    831

    Re: Moment when all interactive user accounts have been logged out

    No, I think I'm about to abandon NetWkstaUserEnum. I'm not sure what accounts it reports on, but it doesn't do what I need -- list of currently logged on interactive users. For instance it keeps returning a user account that was already logged off.

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,485

    Re: Moment when all interactive user accounts have been logged out

    Quote Originally Posted by dc_2000 View Post
    No, I think I'm about to abandon NetWkstaUserEnum. I'm not sure what accounts it reports on, but it doesn't do what I need -- list of currently logged on interactive users. For instance it keeps returning a user account that was already logged off.
    What level are you calling it with and how are you calling it? Are you using NetApiFreeBuffer after each call?

  9. #9
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    831

    Re: Moment when all interactive user accounts have been logged out

    I'm calling it with level 1 using the example from this page.

  10. #10
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,485

    Re: Moment when all interactive user accounts have been logged out

    Quote Originally Posted by dc_2000 View Post
    I'm calling it with level 1 using the example from this page.
    Try it with level 1.

  11. #11
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,854

    Re: Moment when all interactive user accounts have been logged out

    Perhaps a bit late, but have a look at
    LsaEnumerateLogonSessions()
    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    together with
    LsaGetLogonSessionData()
    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    These can be used to retrieve the logon details of the users - including the type of logon, the user name and the name of the domain used to authenticate.

    When calling from a service, I think it only returns info about currently logged on users.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center