davetek Posted April 26, 2007 Share Posted April 26, 2007 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 Link to comment Share on other sites More sharing options...
evilertoaster Posted April 26, 2007 Share Posted April 26, 2007 http://www.autoitscript.com/forum/index.php?showtopic=44818Posted 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 Link to comment Share on other sites More sharing options...
Administrators Jon Posted April 26, 2007 Administrators Share Posted April 26, 2007 A possible way would be to use DriveMapAdd to map a drive to the local c$ share. When you find the DriveMap credentials that work you can then use it for RunAsSet. Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/ Link to comment Share on other sites More sharing options...
PsaltyDS Posted April 26, 2007 Share Posted April 26, 2007 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) EndFuncAs you can see, this obviously much better more fun than Jon's! 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now