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)"
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.
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.
来源:https://stackoverflow.com/questions/12112506/how-to-script-log-in-and-log-out-on-windows-xp