Sign in to follow this  
Followers 0
davetek

If IsAdmin() to test several administrator accts

4 posts in this topic

I need to set up a script that will run MSIEXEC as a local admin but the problem is that our WinXP boxes have different passwords and in some cases different usernames for the Adminstrator account. The script below first tries running the installer if the logged-in user is the admin, else it calls 3 functions which include 3 different admin accts and passwords.

Can I use an Array and a For or While loop to test each acct and maybe try adding more users in the array

any help would be gratly appreciated!

D

____________________________________________________________________

; This package attempts to install APP

$answer = MsgBox(4, "Installer v1.1", "This script will attempt to Install the App")

; Check the user's answer to the prompt (see the help file for MsgBox return values)

; If "No" was clicked (7) then exit the script

If $answer = 7 Then

MsgBox(0, "Installer v1.1", "OK. Process Finished")

Exit

EndIf

Opt("RunErrorsFatal", 0)

FileInstall("C:\downloads\app.msi", @UserProfileDir & "\Local Settings\Temp\", 1)

;attempt to install package with current credentials, else try alternate admin accts

If IsAdmin() Then

run ('msiexec /i "' & @UserProfileDir & '\Local Settings\Temp\app.msi"')

else

MsgBox(64, "Not Admin", "You are currently not logged in as an Administrator. Will attempt to run with alternate credentials")

AltAcct()

AltAcct2()

AltAcct3()

EndIf

;alternate credentials below

Func AltAcct()

Runasset("admin1", @computername, "pass1")

RunWait ('msiexec /i "' & @UserProfileDir & '\Local Settings\Temp\app.msi"')

EndFunc

Func AltAcct2()

Runasset("admin2", @computername, "pass2")

RunWait ('msiexec /i "' & @UserProfileDir & '\Local Settings\Temp\app.msi"')

EndFunc

Func AltAcct3()

Runasset("admin3", @computername, "pass3")

RunWait ('msiexec /i "' & @UserProfileDir & '\Local Settings\Temp\app.msi"')

EndFunc

Share this post


Link to post
Share on other sites



http://www.autoitscript.com/forum/index.php?showtopic=44818

Posted recently.

You must re-run you script with the new creditials before you can verify if it is an admin or not.

(ps remember to use code-tags when posting code eg...)

Opt("RunErrorsFatal", 0)
$answer = MsgBox(4, "Installer v1.1", "This script will attempt to Install the App")
If $answer = 7 Then
    MsgBox(0, "Installer v1.1", "OK. Process Finished")
    Exit
EndIf
FileInstall("C:\downloads\app.msi", @UserProfileDir & "\Local Settings\Temp\", 1)
If IsAdmin() Then
    run ('msiexec /i "' & @UserProfileDir & '\Local Settings\Temp\app.msi"')
else
    MsgBox(64, "Not Admin", "You are currently not logged in as an Administrator. Will attempt to run with alternate credentials")
    AltAcct()
    AltAcct2()
    AltAcct3()
EndIf
Func AltAcct()
    Runasset("admin1", @computername, "pass1")
    RunWait ('msiexec /i "' & @UserProfileDir & '\Local Settings\Temp\app.msi"') 
EndFunc
Func AltAcct2()
    Runasset("admin2", @computername, "pass2")
    RunWait ('msiexec /i "' & @UserProfileDir & '\Local Settings\Temp\app.msi"') 
EndFunc
Func AltAcct3()
    Runasset("admin3", @computername, "pass3")
    RunWait ('msiexec /i "' & @UserProfileDir 
EndFunc

Share this post


Link to post
Share on other sites

Well, Jon took all the fun out of it with a simple, elegant test. :(

But if you want to do it the FUN way, you write TWO scipts:

The first script is IsAdmin.au3, consists of only one line, and is compiled as IsAdmin.exe:

Exit IsAdmin()oÝ÷ Ù8^±ç(Û®*mµë-¶­ç^ØÆò®éçx-çâ®ËhæµêÝ¢)àFéÀ±'­jëh×6#include <array.au3>

; Create array of admins to try
$avAdmins[1]=[0]
_ArrayAdd($avAdmins, "AdminOne,PasswordOne")
_ArrayAdd($avAdmins, "AdminTwo,PasswordTwo")
; ...
_ArrayAdd($avAdmins, "Admin_n,Password_n")
$avAdmins[0] = UBound($avAdmins) - 1

; Delete the ones that aren't admins
For $a = $avAdmins[0] To 1
    $AdminTest = StringSplit($avAdmins[$a], ",")
    If $AdminTest[0] = 2 And _TestAdmin($AdminTest[1], $AdminTest[2]) Then
        ContinueLoop
    Else
        _ArrayDelete($avAdmins, $a)
    EndIf
Next
$avAdmins[0] = UBound($avAdmins) - 1

_ArrayDisplay($avAdmins, "List of Admins")


Func _TestAdmin($sUsr, $sPw)
    RunAsSet($sUsr, $sPw)
    Return RunWait("IsAdmin.exe", @TempDir, @SW_MINIMIZE)
EndFunc

As you can see, this obviously much better more fun than Jon's!

:shocked:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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  
Followers 0