Sign in to follow this  
Followers 0
butterfly888

Logoff current user on WinXP

14 posts in this topic

Real newbie here...

Can someone tell me how to create a script that logs off the current user on WinXP and then enters the username/password for a different user to login windows. I saw Shutdown in Help topics but what do I use with Shutdown to login the new user?

Thanks.

Share this post


Link to post
Share on other sites



logs off the current user on WinXP

This will get you logged off:

shutdown -l

But this:

enters the username/password for a different user to login windows

is an entirely different ball of wax. I don't know if that even can be done as the program launched under one user who logs will likely be killed in the logoff.

Share this post


Link to post
Share on other sites

is an entirely different ball of wax. I don't know if that even can be done as the program launched under one user who logs will likely be killed in the logoff.

I also have the interesting of logoning windows system automatically with tools like AutoIT. Is is really impossible? Is there anyone who have something to say about this topic?

Thanks

Sunzen

Share this post


Link to post
Share on other sites

You can set the PC to auto login with predefined credentials.

It will not ask for user name and password and just log in.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Basically, the logon window runs under a separate desktop, and is heavily protected against sending of keystrokes to it. Hence this approach is extremely difficult. The simplest workaround is to use autologon, which involves creating some registry values in the Winlogon key,

$Winlogon="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
RegWrite($Winlogon,"DefaultPassword","REG_SZ","noneofyourbusiness")
RegWrite($Winlogon,"DefaultUserName","REG_SZ","myname")
RegWrite($Winlogon,"AutoAdminLogon","REG_SZ","1")
RegWrite($Winlogon,"ForceAutoLogon","REG_SZ","1")
$tmp=RegRead($Winlogon,"DefaultDomainName")
if @error then RegWrite($Winlogon,"DefaultDomainName","REG_SZ",@computername)

When set correctly a shutdown command will result in an immediate re-logon with the credentials given. To prevent this, hold shift whilst issuing shutdown.

Slight disadvantage is that anyone who knows how to use regedit can find the password, as it has to be plaintext.

http://support.microsoft.com/?kbid=315231

Other approach would be to use 'control userpasswords2' and Send() the keystrokes required to it. You still need to set ForceAutoLogon directly though.

Edited by Anteaus

Share this post


Link to post
Share on other sites

This will get you logged off:

shutdown -l

But this:

is an entirely different ball of wax. I don't know if that even can be done as the program launched under one user who logs will likely be killed in the logoff.

Yeah, I was thinking the same thing that the script would be killed. Ok, thanks for your input.

Share this post


Link to post
Share on other sites

Basically, the logon window runs under a separate desktop, and is heavily protected against sending of keystrokes to it. Hence this approach is extremely difficult. The simplest workaround is to use autologon, which involves creating some registry values in the Winlogon key,

$Winlogon="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
RegWrite($Winlogon,"DefaultPassword","REG_SZ","noneofyourbusiness")
RegWrite($Winlogon,"DefaultUserName","REG_SZ","myname")
RegWrite($Winlogon,"AutoAdminLogon","REG_SZ","1")
RegWrite($Winlogon,"ForceAutoLogon","REG_SZ","1")
$tmp=RegRead($Winlogon,"DefaultDomainName")
if @error then RegWrite($Winlogon,"DefaultDomainName","REG_SZ",@computername)

When set correctly a shutdown command will result in an immediate re-logon with the credentials given. To prevent this, hold shift whilst issuing shutdown.

Slight disadvantage is that anyone who knows how to use regedit can find the password, as it has to be plaintext.

http://support.microsoft.com/?kbid=315231

Other approach would be to use 'control userpasswords2' and Send() the keystrokes required to it. You still need to set ForceAutoLogon directly though.

Yes setting registry values for Winlogon should work for what I'm doing. Since the password displays in plaintext I could remove the value for DefaultPassword after my script runs.

Now the does the user who launches the script need to be a local administrator since values are been set in the registry?

What is this check for?

$tmp=RegRead($Winlogon,"DefaultDomainName")

if @error then RegWrite($Winlogon,"DefaultDomainName","REG_SZ",@computername)

Thanks for our help.

Share this post


Link to post
Share on other sites

Is this to install software? You could do a RunAs to install the application.

No I'm not installing software. I'm running a mult-user application. So user1 launches the script. My script would launch the application, do some things, close the application, logoff user1, then login as user2 to launch the application and do some things. Would RunAs work in this scenario?

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Now the does the user who launches the script need to be a local administrator since values are been set in the registry?

$tmp=RegRead($Winlogon,"DefaultDomainName")

if @error then RegWrite($Winlogon,"DefaultDomainName","REG_SZ",@computername)

Yes, to set the values, but not to autologon once set.

The check is in case the domain isn't set. (if the computer is an AD member we don't want to disturb any existing value)

RunAs will work in most cases if you just need to test an app under different credentials.

Edited by Anteaus

Share this post


Link to post
Share on other sites

Yes, to set the values, but not to autologon once set.

The check is in case the domain isn't set. (if the computer is an AD member we don't want to disturb any existing value)

RunAs will work in most cases if you just need to test an app under different credentials.

Ok cool. Thanks again for you help and speedy responses. :mellow:

Share this post


Link to post
Share on other sites

This is a UDF several people + me worked on a while back to do exactly this:

http://www.autoitscript.com/forum/index.php?showtopic=94609

Share this post


Link to post
Share on other sites

This is a UDF several people + me worked on a while back to do exactly this:

http://www.autoitscript.com/forum/index.php?showtopic=94609

Ok cool, I'll check it out. Thank you.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0