Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need a script to determine password 1

Status
Not open for further replies.
May 31, 2006
237
US
At our school, we have at least three different desktop images floating around, and each one has a different Administrator password. Luckily, they all use the same Administrator account. However, I'm trying to create a batch file that will use lsrunas to run a command as the administrator account and automatically pass the password along to it, based on what password is in place. The problem I'm encountering is that lsrunas doesn't return an errorlevel, but runas does. However, runas doesn't allow the command line to pass the password to it either via pipe or redirect ( | or < ). The logic of the script should be something like this:

FOR pass IN (pass1, pass2, pass3) DO
lsrunas /user:administrator /password:%pass% /domain:%COMPUTERNAME% /command:[any command] /runpath:[path of command]
IF %ERRORLEVEL%=="0" THEN BREAK
ELSE
DONE

I'm better at bash shell scripting so forgive me if my syntax is wrong in the FOR statement.

The above WOULD work, except lsrunas always returns ERRORLEVEL=0, whether the password is good or not. runas at least returns ERRORLEVEL=1 when the password is bad, and =0 when the password is good.

Any ideas? Thanks.
 
What difference does it make?
If the 3rd is the correct password, then 2 runs will fail before the correct one eventually kicks in, why try to catch a few seconds trying to end the loop if the first or second password fits, and the second/third run fails?

HTH
 
OK then would it be correct syntax to do the following, accepting that two attempts will fail and the third will succeed?

FOR pass IN (pass1, pass2, pass3) DO lsrunas /user:administrator /password:%pass% /domain:%COMPUTERNAME% /command:[any command] /runpath:[path of command]

And this will run the same command three times, each with a different password (as specified in pass1, pass2, pass3)?

Again I'm better at bash shell scripting than DOS batch file programming, I'm just wondering about the syntax of the FOR command.

Thanks!
 
Type
Code:
help for
in a command prompt window to get help on the 'for' command.

HTH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top