krispoet Posted September 7, 2010 Share Posted September 7, 2010 Hi Just a reference post for those who want to use Autoit to run executable as administrator I was trying to rewrite an old autoit script from using RunAsSet() & switch to Run() / RunWait() as the newer AutoIt deprecated RunAsSet() The following example helps you to kill all the Excel process on the machine then map network drive as another user & copy files to where your script relies This is not meant to be secure / just a dirty fix for your environment~ I am sure if you search further, you would find much better script the following~~ Hope this help some admins around $sUserName = 'Administrator' $sPassword = 'Adminpassword' $ExePath = "T:\Admin.exe" If IsAdmin() Then $Answer = MsgBox(4100, "My App Installer", "Do you want to close Excel?",10) If $Answer =6 Then ;Kill all excel.exe process ShellExecute("taskkill.exe", "/f /im excel.exe",@SW_HIDE) ; Map repository drive with domain user's credentials, then copy Admin.exe to @scriptDir ShellExecute('cmd.exe', '/c net use T: \\fs01\repo /user:mydomain\user01 user01password && copy '& $ExePath & " " & @ScriptDir ) ;Execute the copied program as administrator RunWait("Admin.exe",@ScriptDir ) Else EndIf Else ;The following command rerun the script as Admin, so the user could run the executable with admin privilege without knowing the password RunAs($sUserName, @ComputerName, $sPassword, 0, @AutoItExe & ' /RunAs', 'C:\WIndows\System32', @SW_HIDE) EndIf 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