Jump to content

Running script as local admin not knowing which password to use


Recommended Posts

Hiya All,

I need to create a script to run as the local admin on WinXP (SP2/3) machines. These machines would be off site and not currently connected to the domain, so I can't simply use network install ID and password.

The issue I'm having is how to set the script to run when the local admin password might be one of three different options...

Basically due to the idea that the sales reps don't get into the office all that often.

My entire script works; however, it only works when I know which of the passwords to use and I don't really want to create three different scripts for the three different flavors of the passwords.

Is this possible to do? If so, a pointer to the right direction would be greatly appreciated.

The only thing I can think of doing is to run calc.exe with each admin/pw combo and then a check for the calculator window

Thanks,

Mike

Edited by MikeDub
Link to comment
Share on other sites

Are Usernames not paired with passwords?

In Network they are. These are remote sales people's computers. Since they don't make it into the office all that often, they don't get the Local Admin password changes that happen every so often

Link to comment
Share on other sites

For example, try adding this to the top of your script. Note: Passwords are in clear text. This is with a single user account that may have multiple passwords.

Global $sProgramName = "Run As Admin " & StringTrimRight(@ScriptName, 4)
If WinExists($sProgramName) Then Exit; To prevent the script from running itself over and over and over if the specified admin user is not found...

AutoItWinSetTitle($sProgramName) ; To prevent the script from running itself over and over and over if the specified admin user is not found...

Global $sAdminUser = "UserName"
Global $sDomain = @ComputerName
Global $aAdminPasswords[3] = ["Password1", "Password2", "Password3"]

MsgBox(0, "Test 1", "This is a test"& @CRLF & @UserName & @CRLF & $sAdminUser & @CRLF & IsAdmin())

If @UserName <> $sAdminUser And Not IsAdmin() And @Compiled Then
For $iPWNum = 0 To UBound($aAdminPasswords) - 1 Step 1
MsgBox(0, "Run Admin", $sAdminUser & @CRLF & $sDomain & @CRLF & $aAdminPasswords[$iPWNum])
If RunAs($sAdminUser, $sDomain, $aAdminPasswords[$iPWNum], 0, @AutoItExe) Then ExitLoop
Next

    Exit
EndIf


MsgBox(0, "Test 2", "This is a test"& @CRLF & @UserName & @CRLF & $sAdminUser & @CRLF & IsAdmin())

Edit: Updated code.

Adam

Edited by AdamUL
Link to comment
Share on other sites

For example, try adding this to the top of your script. Note: Passwords are in clear text. This is with a single user account that may have multiple passwords.

Removed to save space

Edit: Updated code.

Adam

Using this below code, I can't get it to even run calculator

Global $sProgramName = "Run As Admin " & StringTrimRight(@ScriptName, 4)
; To prevent the script from running itself over and over and over if the specified admin user is not found...
If WinExists($sProgramName) Then Exit
; To prevent the script from running itself over and over and over if the specified admin user is not found...
AutoItWinSetTitle($sProgramName)
Global $sAdminUser = "TheID_I_Tested"
Global $sDomain = @ComputerName
Global $aAdminPasswords[3] = ["pass","pass1","pass3"]
Global $sRun = "C:\Windows\System32\Calc.exe"
If @UserName <> $sAdminUser And Not IsAdmin() And @Compiled Then
For $iPWNum = 0 To UBound($aAdminPasswords) - 1 Step 1
RunAs($sAdminUser, $sDomain, $aAdminPasswords[$iPWNum], 0, $sRun)
If Not @error Then ExitLoop
Next
    Exit
EndIf
MsgBox(0, "Test", "Script Completed"& @CRLF & @UserName & @CRLF & IsAdmin())

Edit: There are no errors, it simply displays the MsgBox text

Edited by MikeDub
Link to comment
Share on other sites

It will not run calculator. The code I posted was meant to rerun the script itself with Admin privileges, not another executable.

To do that, try this.

Global $sAdminUser = "TheID_I_Tested"
Global $sDomain = @ComputerName
Global $aAdminPasswords[3] = ["pass","pass1","pass3"]
Global $sRun = "C:\Windows\System32\Calc.exe"


For $iPWNum = 0 To UBound($aAdminPasswords) - 1 Step 1
$iPID = RunAs($sAdminUser, $sDomain, $aAdminPasswords[$iPWNum], 0, $sRun)
If ProcessExists($iPID) Then ExitLoop
Next

I also updated my code in my first post.

Adam

Link to comment
Share on other sites

It will not run calculator. The code I posted was meant to rerun the script itself with Admin privileges, not another executable.

To do that, try this.

Global $sAdminUser = "TheID_I_Tested"
Global $sDomain = @ComputerName
Global $aAdminPasswords[3] = ["pass","pass1","pass3"]
Global $sRun = "C:\Windows\System32\Calc.exe"


For $iPWNum = 0 To UBound($aAdminPasswords) - 1 Step 1
$iPID = RunAs($sAdminUser, $sDomain, $aAdminPasswords[$iPWNum], 0, $sRun)
If ProcessExists($iPID) Then ExitLoop
Next

I also updated my code in my first post.

Adam

That does it !! Thanks Much Adam, you've helped me solve many headaches I see coming in the future :)

EDIT: The problem I was having with the other way, was that it would display the message box, even when I'd change the array of passwords to bogus passwords. I will admit that I was going on the notion that the msgbox would only display if the right combo of ID and Password was found

Edited by MikeDub
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...