Jump to content
Sign in to follow this  
EricL

RunAsSet after determine current admin password

Recommended Posts

EricL

on my network I have a few local admin passwords on clients.

I want to do a runasset to execute the setup as a local admin. however over time the pw change and I have 2 different passwords.

Is there a way i can test the local admin, and get a result returned fail or pass.

basically...

;Vista
if @OSVersion = "WIN_VISTA" Then
RunAsSet('administrator', @Computername, 'password1')
    RunWait("msiexec /i C:\file.msi /qb+!")
Else
    If Not IsAdmin() Then
                     IF <<<< insert test string?>>>> Then
         RunAsSet('administrator', @Computername, 'password1')
         run("msiexec /i C:\file.msi /qb+!")
                     ELSE
         RunAsSet('administrator', @Computername, 'password2')
         run("msiexec /i C:\file.msi /qb+!")                     
                Else
    run("msiexec /i C:\file.msi /qb+!")
    EndIf
EndIf
RunAsSet()

I may be way off.. please advise.

Also does the code look right? I never did anything this complicated yet. still learning.

TIA!

Edited by EricL

Share this post


Link to post
Share on other sites
EricL

This work but it's a bit ugly:

First compile this code:

#RequireAdmin
Exit 1oÝ÷ Ù8^*.q©î±ëayì^)¶¬jëh×6$code=RunAsWait("Andreas",@ComputerName,"password",0,"nameofcompiledexe.exe")
If $code=1 Then 
MsgBox(0,"","Right pass!")
Else
MsgBox(0,"","Wrong pass :(")
EndIf
Im trying this.. did you mean to put the last part? you can run the exe from teh RunAsSet function? I assume you meant RunAsSet since RunAsWait does not exist?

Thanks for your help!

Share this post


Link to post
Share on other sites
monoceres

Im trying this.. did you mean to put the last part? you can run the exe from teh RunAsSet function? I assume you meant RunAsSet since RunAsWait does not exist?

Thanks for your help!

RunAsWait() is part of the latest beta :D


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
EricL

RunAsWait() is part of the latest beta :D

oh. heh.

Is there a way to do it w/ non-beta?

I tried it a few ways and the problem is its generating errors that logon is no good (popup erros then exit.)

I cant get it to just keep chugging to the else statement.

Share this post


Link to post
Share on other sites
Jos

Something like this should work"

RunAsSet("ID1", @ComputerName, 'Psw1')
RunWait(@ComSpec & " /c dir ", "", @SW_HIDE)
If @error = 0 Then
    $Cur_SEQ = 0
Else
    RunAsSet("ID2", @ComputerName, 'Psw2')
    RunWait(@ComSpec & " /c dir ", "", @SW_HIDE)
    If @error = 0 Then
        $Cur_SEQ = 1
    Else
        MsgBox(4096, "Admin account", "Unknown")
        Exit
    EndIf
EndIf

:D

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
EricL

Something like this should work"

RunAsSet("ID1", @ComputerName, 'Psw1')
RunWait(@ComSpec & " /c dir ", "", @SW_HIDE)
If @error = 0 Then
    $Cur_SEQ = 0
Else
    RunAsSet("ID2", @ComputerName, 'Psw2')
    RunWait(@ComSpec & " /c dir ", "", @SW_HIDE)
    If @error = 0 Then
        $Cur_SEQ = 1
    Else
        MsgBox(4096, "Admin account", "Unknown")
        Exit
    EndIf
EndIf

:D

Ok i tried to follow this. I think i get it. not 100% sure what this does "RunWait(@ComSpec & " /c dir ", "", @SW_HIDE)"

but I dont think sw_hide worked. I get the same error as before.

popup that says it was unable to execute the comspec runwait command due to logon error.

Share this post


Link to post
Share on other sites
Jos

You need this at the top of the script to tell AUtoIt to continue on RUN errors:

Opt("RunErrorsFatal", 0)

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
EricL

You need this at the top of the script to tell AUtoIt to continue on RUN errors:

Opt("RunErrorsFatal", 0)

Jos

Money! :D

Sweet thanks!!!

Share this post


Link to post
Share on other sites
bikester

I need to share this since i spent a fair amount of time looking for the same type of solution.

The basis of this script came from another user and i can't find the original post right now. We have a couple thousand pc's and maybe a total of 10 possible passwords that could be on the local administrator account or on other admin accounts. Now that i have this working, it is in every installer package i make. I obfuscate and compile before releasing to the masses, or running in a script.

Just add as many username / password combos that you need. It allows you to purposely have many different admin logins so that if one is compromised, your entire network is not at risk. I made a special admincheck utility out of this, that actually displays the correct username and password so you don't spend 15 mins trying different ones. Obviously that is a super secret program just for the techs.

#include <Array.au3>

Global $user, $pw

AdminCheck()

If $user="unknown" or $user="" Then
    MsgBox(0, "", "Authentication Error")
    Exit
EndIf

RunAsSet($user, @ComputerName, $pw, 0)
RunWait(@ComSpec & " /c " & "c:\temp\setup.exe", "", @SW_HIDE)

; ==> end of script

Func AdminCheck()
    Opt("RunErrorsFatal", 0)
    Global $user="unknown", $pw="unknown"

    Local $avAdmins[1]
    _ArrayAdd($avAdmins, "admin1,password1")
    _ArrayAdd($avAdmins, "admin2,password2")
    _ArrayAdd($avAdmins, "admin3,password3")

    For $i = 1 to UBound($avAdmins) - 1
        $AdminTest = StringSplit($avAdmins[$i], ",")
        RunAsSet($AdminTest[1], @ComputerName, $AdminTest[2], 0)
        RunWait(@ComSpec & " /c " & "echo Running on the "& $AdminTest[1] &" account!>"&@WindowsDir&"\au3admchk.tmp", "", @SW_HIDE)
            If not @error Then
                Global $user = $AdminTest[1]
                Global $pw = $AdminTest[2]
                ExitLoop
            EndIf
    Next

Opt("RunErrorsFatal", 1)

   If FileExists(@WindowsDir &"\au3admchk.tmp") Then
    RunAsSet($user, @ComputerName, $pw, 0)
    Run(@ComSpec & " /c del " & @WindowsDir & "\au3admchk.tmp", "", @SW_HIDE)
   EndIf

RunAsSet()

EndFunc

Share this post


Link to post
Share on other sites
EricL

There is stuff in there that I dont understand yet. ie; #include etc.

I am very glad you posted this as i will try and figure it out if i need more than the current 2 local pw's.

Thanks alot!

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  

×