Jump to content

Recommended Posts

Posted

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.

Posted

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.
Posted

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

Posted

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

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

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
Posted

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.
Posted

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.

Posted

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?

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
Posted

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:

Posted

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.

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
×
×
  • Create New...