dobbelina Posted April 9, 2010 Share Posted April 9, 2010 (edited) Hi everyone! Long time since i did some Autoit stuff, but now i'm hooked again by this fantastic little script engine. I saw a few threads about re-running the same script with admin credentials. Similar to this: Local $user = "Administrator" Local $pass = "Password" If Not IsAdmin() Then RunAs($user, @ComputerName, $pass, 0, @ScriptName, @ScriptDir) Exit EndIf MsgBox(48, "Success!", "I Am Admin") But it doesn't work, at least not on my Windows 7 rig? Substituting @ScriptName with "secondary.bat" works, but is not as sexy as above. One can always execute external bat or cmd files, and then do the shuffling via temp folder. But wouldn't it be neat to to be able to re-run the same script as admin. Comments... Edited April 9, 2010 by dobbelina Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted April 9, 2010 Share Posted April 9, 2010 (edited) That doesn't make much sense to me. Are you trying to run a .au3 or .exe? .au3 files aren't executable so you need to use the @AutoItExe in that case. Edited April 9, 2010 by AdmiralAlkex .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
dobbelina Posted April 9, 2010 Author Share Posted April 9, 2010 Ahh, okay. Probably wishfull thinking then from my part. I saw a thread where a guy claimed he did it this way. I'll just let it run external files with admin cred then. Thanks for replying Link to comment Share on other sites More sharing options...
dobbelina Posted April 9, 2010 Author Share Posted April 9, 2010 Uhh, wait now, i just had my coffe. So using @AutoItExe instead of @ScriptName work you mean ? (I don't have my own computer in front of me) Link to comment Share on other sites More sharing options...
MHz Posted April 9, 2010 Share Posted April 9, 2010 This may work as untested. It will restart whether compiled or not. Local $user = "Administrator" Local $pass = "Password" ; test passed switch to prevent multiple executions if something goes weird If Not IsAdmin() And Not $CMDLINE[0] Then RunAs($user, @ComputerName, $pass, 0, _ '"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & @ScriptFullPath & '" /restart', _ @ScriptDir) Exit EndIf MsgBox(48, "Success!", "I Am Admin") Link to comment Share on other sites More sharing options...
dobbelina Posted April 9, 2010 Author Share Posted April 9, 2010 Wow ! That works, and i don't need to compile all the time for testing to. Big thanks! , you guys rock Link to comment Share on other sites More sharing options...
neebo Posted February 18, 2011 Share Posted February 18, 2011 (edited) Since I have to be able to manage a great number of computers with different admin accounts (four) on each one, can this script be modified in a way, that: - it checks IsAdmin(), if not, restart as adminuser1 - it checks IsAdmin(), if not, restart as adminuser2 - it checks IsAdmin(), if not, restart as adminuser3 - it checks IsAdmin(), if not, restart as adminuser4 - in case of fail, close script. Tried with this script. Works ok on Win XP, fails in Win 7 expandcollapse popup#include<Array.au3> $countFile = (@ScriptDir & "\count.txt") $countFileCopy = (@ScriptDir & "\count_copy.txt") Local $userArray[5] $userArray[0] = "" $userArray[1] = "admin1" $userArray[2] = "admin2" $userArray[3] = "admin3" $userArray[4] = "admin4" Local $passArray[5] $passArray[0] = "" $passArray[1] = "pass1" $passArray[2] = "pass2" $passArray[3] = "pass3" $passArray[4] = "pass4" If Not FileExists($countFile) Then ; if countfile dont exist, create it FileOpen($countFile, 1) $count = 0 FileWrite($countFile, $count) FileClose($countFile) FileOpen($countFile, 0) $count = FileReadLine($countFile, 1) FileClose($countFile) Else ; if countfile exists, read it FileOpen($countFile, 0) $count = FileReadLine($countFile, 1) If $count > 5 Then MsgBox(0, "ERROR", "No more passwords") Exit EndIf EndIf If Not IsAdmin() And Not $CMDLINE[0] Then MsgBox(0, $count, "NOT ADMIN", 5) RunAs($userArray[$count], @ComputerName, $passArray[$count], 0, _ '"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & @ScriptFullPath & '" /restart', _ @ScriptDir) $count = $count + 1 FileWrite($countFile, $count) FileClose($countFile) Exit EndIf ;check if restart was succesful If IsAdmin() Then MsgBox(0, $userArray[$count], "IS ADMIN", 3) Else MsgBox(0, $userArray[$count], "IS NOT ADMIN", 3) Exit EndIf Run('whatever.exe') FileClose($countFile) FileCopy($countFile, $countFileCopy) FileDelete($countFile) Exit Edited February 18, 2011 by neebo 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