Question

Our clients have computers with 4 different possible local administrator passwords. I am wanting to put together a silent batch file within an EXE file so that the batch file cannot easily be read by users that installs a piece of software. Not secure but this is the way we need it at the moment.

I am using PSEXEC and want the script to attempt to run the program with each password and then terminate the script once the installer has launched successfully - without trying the other passwords. For example, if the second password is correct then PSEXEC should have only been ran twice.

Here is the script. At the moment it is trying all 4 passwords even though the second password is correct and the program installer launches.

@ECHO OFF
cd %cd%


echo 1
psexec -user administrator -p Password1 -i -d -c -f "FirefoxSetup28.0.exe" /accepteula 2>>log1.txt
find /i "unknown user name or bad password" log1.txt > nul


if errorlevel=0 (

del log1.txt /F
cls
ver > nul
echo 2
psexec -user administrator -p Password2 -i -d -c -f "FirefoxSetup28.0.exe" /accepteula 2>>log2.txt
find /i "unknown user name or bad password" log2.txt > nul

if errorlevel=0 (


del log2.txt /F
cls
ver > nul
echo 2
psexec -user administrator -p Password3 -i -d -c -f "FirefoxSetup28.0.exe" /accepteula 2>>log3.txt
find /i "unknown user name or bad password" log3.txt > nul


if errorlevel=0 (

del log3.txt /F
cls
ver > nul
echo 3
psexec -user administrator -p Password4 -i -d -c -f "FirefoxSetup28.0.exe" /accepteula 2>>log4.txt
find /i "unknown user name or bad password" log4.txt > nul

if errorlevel=0 (

del log4.txt /F
echo Unable to install program
pause

) else (

del log4.txt /F
break
exit

)

) else (

del log3.txt /F
break
exit

)


) else (

del log2.txt /F
break
exit

)


) else (

del log1.txt /F
break
exit


)

exit

Here is an example of the log1.txt file:

PsExec v1.98 - Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals - www.sysinternals.com

Logon failure: unknown user name or bad password.

PsExec could not start FirefoxSetup28.0.exe:
Was it helpful?

Solution

The syntax of the if statement is if string1==string2 (there are other comparison operators...)

errorlevel will never be equal to 0 because the strings "errorlevel" and "0" are compared.

The syntax you need is either

if errorlevel 1 (dothisthing if errorlevel is 1 or greater) else (dothatif errorlevel is less than 1)

or

if not errorlevel 1 (dothisif errorlevel is less than 1)

furthermore, break does nothing under Windows (see break /? from the prompt for docco)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top