programmatically log on / log off users



Hi

I have service running under the service account. I'd like it to perform the
following functions:

1) Check if a certain user (based on his username and domain) has an active
session, be it on the local console or via terminal service.
2) If the user has a session, I'd like to terminate that session (no
questions asked, regardless of whether the user still has a document open)
3) Then I'd like to make sure that another user is logged in via local
console, so when you get to the machine, no login and password has to be
provided.

I know that ExitWindowEx can be used to log out the current user, but so far
I only have experience in doing this from the system console (so the app
executing the code is running on the logged on user's permission set) -
would it work from a service as well and if there are multiple active
sessions (suppose an admin logged on via console, then another user tried
via remote desktop and the admin allowed access resulting in two sessions on
the machine with the user's session being the active one) which session
would be logged out?

As far as logging in goes, I found LogonUser. I've written a small
commandline app which calls LogonUser with valid credentials, and
dwLogonType set to LOGON32_LOGON_INTERACTIVE. I get a positive response, yet
besides that nothing happens. When launched from the local console,
shouldn't that result in the current user being logged out and the new user
being logged in?

Last but not least I'm rather clueless as to listing active sessions so I'd
appreciate any tips.

Regards
Stephan


.



Relevant Pages

  • Re: WTSQuerySessionInformation
    ... Session zero has stopped being `the console session` starting from Vista. ...
    (microsoft.public.win32.programmer.kernel)
  • programmatically log on / logg off user
    ... I have service running under the service account. ... be it on the local console or via terminal service. ... If the user has a session, I'd like to terminate that session (no ...
    (microsoft.public.platformsdk.security)
  • Re: WTSQuerySessionInformation
    ... Yes we agree that if the console is in the middle of changing ownership then it's not clear what I should do. ... the Terminal Services console session. ... then either I'm running on the physical console and a normal user or other ... This page doesn't single out Windows Vista. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: 2.4.10-r1 MTRR bug
    ... > console is frozen from further output (but it doesn't prevent the full ... > Linux/X session, but not able to regain any virtual console session.) ... 0000:00:02.7 Multimedia audio controller: Silicon Integrated Systems ...
    (Linux-Kernel)
  • Re: Remote Desktop to XP Pro Problems
    ... "console" shouldn't matter much one way or another (Vista and Longhorn ... reserve the console session, session 0, for services; ... behavior of RDP sessions set in the Terminal Services portion of GP? ... There are numerous other ways to shutdown ...
    (microsoft.public.windows.terminal_services)