1

I've found several posts on this site and the internet describing how to log out the current user, but how can I log in a specific user?

Log out (cygwin) can be accomplished this way:

echo "\n" | powershell -ExecutionPolicy RemoteSigned "(gwmi Win32_OperatingSystem).Win32Shutdown(0)"
1
  • Log out can also be accomplished as shutdown -l ^_^ Commented Aug 24, 2012 at 15:41

2 Answers 2

0

Well here's how you would log out a specific user:

function getsessionid($username, $server)
{
   query session $username "/SERVER:$server" |?{$_ -match "$userName\s+(\d+)\s"} |%{ $matches[1] }
}

$id = getsessionid john db123.contoso.net
logoff $id /SERVER:db123.contoso.net

To log someone in, it seems tougher. Take a look here and here.

Sign up to request clarification or add additional context in comments.

Comments

0

You can log in a user with the AutoAdminLogon feature.

To store the password in encrypted rather than plaintext form, see here.

After configuring automatic logon, you will need to reboot the computer in order to make the logon happen. You can bypass the need for a reboot by using a custom GINA, although this is a bit complicated and does not work on Vista or later.

6 Comments

I'm specifically interested in explicitly logging out user X and logging user X back in again in some scripted way - I'm using the auto admin for the normal function of this image. I guess worse case I could simply 'restart' the computer to log in again, but that isn't ideal. Is there really no programmatic way to login and out of windows XP?
If the user account was logged in automatically, and you've set the ForceAutoLogon option, it should log back in automatically each time you log off. Does that help?
For Windows XP only (not Vista or later) one alternative is a custom GINA. I used to successfully use this approach to avoid needing a reboot. If you email me (see my profile) I'll send you a copy of my old code when I get back to work on Monday.
Note also that non-interactive logons (if you need to run code in a particular user's context but don't need a GUI) are reasonably straightforward. From context, however, I assume that you're only interested in interactive logons.
I'm trying to automate system setup like this: one account is setup with a login script that starts my supported program (using force autologin). Our current upgrade process is to manually log out, do our upgrade, and then login. I was hoping an automated logout and login could be accomplished, but if not I guess I could change the automated version of an upgrade so that our app isn't started during the login process, and just put it all back and logout again to start things up again...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.