komradekristoph Posted July 25, 2014 Posted July 25, 2014 Hi everyone Nice to meet you all! This is my first venture into using AutoIT so please be gentle lol Also I did do some research and have tried different variations on the script I need before making this post... Basically I would like a script to compile as an exe which can be copied to a machine and run under a locked down user account, this exe would allow software to be un-installed mainly using msiexec. It would need to use the built in local administrator account credentials to do this. The first application using the following un-install string which I grabbed from the following registry key: HKLMSOFTWAREMicrosoftWindowsCurrentVersionUninstall MsiExec.exe /I{AF4FCC6E-88E8-4541-9CC2-254B8195BCD2} Does someone have an example script they could provide which I can modify please? It would need to be interactive as we have a department that manages certain pieces of software, we don't want them to have local admin rights...instead they can RDP into a machine, use this exe and manage the software that way. I managed to find a script that suits my needs for installing software via an exe/msi so that side is sorted. Also is it possible to create a script that uses msiexec but allows you to provide your own syntax details? Thank you in advance. Kind regards. Kris
javiwhite Posted July 25, 2014 Posted July 25, 2014 (edited) Hey Kris, Welcome to the AutoIT forums I think the function you're looking for is RunAS An Example would be: local $username = 'administrator' local $domain = '.' local $password = 'password' local $msiexeclocation = 'c:\windows\system32\Msiexec.exe' local $parameters = '/I{AF4FCC6E-88E8-4541-9CC2-254B8195BCD2}' local $hRun = RunAs($username,$domain,$password,0,@comspec & ' /c ' & $Msiexeclocation & ' ' & $parameters,'',@SW_HIDE) If you predeclare all the variables in the above, then you should be able to run the application as an administrator. Alternatively you can add '#REQUIREADMIN' to the top of your script, Which will prompt UAC every time the script is run. The above script will open a Cmd window and execute the command through that. The @SW_HIDE flag will hide the cmd window, so the user won't see the window appear. For testing purposes it's probably best to set this to @SW_SHOW however. Hopefully this'll get you on the right tracks - Javi Edited July 25, 2014 by javiwhite give a man an application, and he'll be frustrated for the day, Teach him how to program applications and he'll be frustrated for a lifetime.
komradekristoph Posted July 25, 2014 Author Posted July 25, 2014 Hi javiwhite Thanks for the rapid reply...and for the example! I did some messing and got the result I needed using the following code: Local $sUserName = "username" Local $sPassWord = "password" Local $sDomain = @ComputerName Local $sProgram = "msiexec /i {AF4FCC6E-88E8-4541-9CC2-254B8195BCD2}" RunAs ($sUserName, $sDomain, $sPassWord, 0, $sProgram) Thank you for your script though, I will save that too for later use! Is there a way to set the script up so it can ask for the application string so it can be used for multiple applications? Regards. Kris
Moderators JLogan3o13 Posted July 25, 2014 Moderators Posted July 25, 2014 Yes, you could use FileOpenDialog. I have used something like this in the past: $msi = FileOpenDialog("Install Wizard", "C:", "MSI (*.msi)") ShellExecute("msiexec.exe", "/i " & $msi & " /qb") "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
komradekristoph Posted July 25, 2014 Author Posted July 25, 2014 (edited) Hi JLogan3o13 Thanks for your quick reply...what if the particular application in question doesn't have an *.msi file? This one uses the msiexec process along with the application string in order to un-install itself. msiexec /i {AF4FCC6E-88E8-4541-9CC2-254B8195BCD2} Is there a way the script can call the msiexec process then ask for a particular string for a certain application? Regards. Kris Edited July 25, 2014 by komradekristoph
Moderators JLogan3o13 Posted July 25, 2014 Moderators Posted July 25, 2014 If you're looking for uninstall rather than install, there are a couple of different ways to go about it. You could... poll the registry and produce a list of apps based on search criteria. Right-click to uninstall. (thanks to both JSThePatriot and ripdad): expandcollapse popup#include <GuiListView.au3> Opt("TrayAutoPause", 0) Opt('GUIOnEventMode', 1) Opt('GUICloseOnEsc' , 1) Global $i Local $sSft Global $sGui = GUICreate('Currently Installed Software', 810, 650, -1, -1) Global $sLvw = GUICtrlCreateListView('#|Installed Software|Display Version|Publisher|Uninstall String', 5, 5, 800, 600) _ComputerGetSoftware($sSft) For $i = 1 To ubound($sSft) - 1 GUICtrlCreateListViewItem($i & '|' & $sSft[$i][0] & '|' & $sSft[$i][1] & '|' & $sSft[$i][2] & '|' & $sSft[$i][3], $sLvw) Next GUICtrlSendMsg($sLvw, 0x101E, 1, 17) GUICtrlSendMsg($sLvw, 0x101E, 2, 65) GUICtrlSendMsg($sLvw, 0x101E, 3, 150) GUICtrlSendMsg($sLvw, 0x101E, 4, 350) Local $mMen = GUICtrlCreateContextMenu($sLvw) Local $CopI = GUICtrlCreateMenuItem('Uninstall Current Selection', $mMen) GUICtrlSetOnEvent($CopI, '_Uninstall') Local $exp = GUICtrlCreateButton(' Expand ', 720, 615) GUICtrlSetOnEvent($exp, '_Expand') GUISetOnEvent(-3, '_AllExit') GUISetState(@SW_SHOW, $sGui) While 1 Sleep(10) WEnd ; Func _AllExit() GUIDelete($sGui) Exit EndFunc ; Func _Uninstall() Local $proc = StringSplit(GUICtrlRead(GUICtrlRead($sLvw)), '|', 1) If $proc[1] == 0 Then Return -1 If $proc[5] Then ShellExecuteWait ($proc[5]) exit EndFunc ; Func _Copy2Clip() Local $proc = StringSplit(GUICtrlRead(GUICtrlRead($sLvw)), '|', 1) If $proc[1] == 0 Then Return -1 If $proc[5] Then ClipPut($proc[5]) EndFunc ; ; Author JSThePatriot - Modified June 20, 2010 by ripdad Func _ComputerGetSoftware(ByRef $aSoftwareInfo) Local Const $UnInstKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" Local $i = 1 Dim $aSoftwareInfo[1][4] $input = inputbox ("Which Software" , "Which Software would you like to view?", 'ALL') If @Error = 1 Then Exit If $input = 'ALL' Then For $j = 1 To 500 $AppKey = RegEnumKey($UnInstKey, $j) If @error <> 0 Then Exitloop If RegRead($UnInstKey & "\" & $AppKey, "DisplayName") = '' Then ContinueLoop ReDim $aSoftwareInfo[UBound($aSoftwareInfo) + 1][4] $aSoftwareInfo[$i][0] = StringStripWS(StringReplace(RegRead($UnInstKey & "\" & $AppKey, "DisplayName"), " (remove only)", ""), 3) $aSoftwareInfo[$i][1] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "DisplayVersion"), 3) $aSoftwareInfo[$i][2] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "Publisher"), 3) $aSoftwareInfo[$i][3] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "UninstallString"), 3) $i = $i + 1 Next $aSoftwareInfo[0][0] = UBound($aSoftwareInfo, 1) - 1 If $aSoftwareInfo[0][0] < 1 Then SetError(1, 1, 0) Return _ArraySort($aSoftwareInfo) Else For $j = 1 To 500 $AppKey = RegEnumKey($UnInstKey, $j) If @error <> 0 Then Exitloop $Reg = RegRead($UnInstKey & "\" & $AppKey, "DisplayName") $string = stringinstr($Reg, $input) If $string = 0 Then Continueloop ReDim $aSoftwareInfo[UBound($aSoftwareInfo) + 1][4] $aSoftwareInfo[$i][0] = StringStripWS(StringReplace(RegRead($UnInstKey & "\" & $AppKey, "DisplayName"), " (remove only)", ""), 3) $aSoftwareInfo[$i][1] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "DisplayVersion"), 3) $aSoftwareInfo[$i][2] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "Publisher"), 3) $aSoftwareInfo[$i][3] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "UninstallString"), 3) $i = $i + 1 Next $aSoftwareInfo[0][0] = UBound($aSoftwareInfo, 1) - 1 If $aSoftwareInfo[0][0] < 1 Then SetError(1, 1, 0) Return _ArraySort($aSoftwareInfo) Endif EndFunc ; Func _Expand() _GUICtrlListView_SetColumnWidth($sLvw, 1, $LVSCW_AUTOSIZE) _GUICtrlListView_SetColumnWidth($sLvw, 2, $LVSCW_AUTOSIZE) _GUICtrlListView_SetColumnWidth($sLvw, 3, $LVSCW_AUTOSIZE) _GUICtrlListView_SetColumnWidth($sLvw, 4, $LVSCW_AUTOSIZE) EndFunc Or use WMI: #include <MsgBoxConstants.au3> $sName = InputBox("Uninstall Wizard", "Please type the first few letters of the application name to search") $oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & @ComputerName & "\root\cimv2") $aProducts = $oWMI.ExecQuery("Select * from Win32_Product Where Name LIKE '%" & $sName & "%'") For $app in $aProducts $popup = MsgBox($MB_YESNOCANCEL, "Uninstall Wizard", "Would you like to uninstall " & $app.Name & "?") If $popup = $IDYES Then $app.Uninstall() ElseIf $popup = $IDCANCEL Then ExitLoop EndIf Next "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
komradekristoph Posted July 25, 2014 Author Posted July 25, 2014 Thanks JLogan3o13 They are both very useful... Where would I add these lines of code to adapt the script so it would use the local administrator credentials to run, so a locked down user who supports others in the department can uninstall a certain app: Local $sUserName = "username" Local $sPassWord = "password" Local $sDomain = @ComputerName RunAs ($sUserName, $sDomain, $sPassWord, 0, $sProgram) Thanks in advance. Kris
Moderators Solution JLogan3o13 Posted July 25, 2014 Moderators Solution Posted July 25, 2014 I would personally choose whichever you want to use, registry or WMI, and compile that one to an executable. I would then create a second script, and use it to install and run the first, like so: (compile first script to C:Uninstall.exe) FileInstall("C:\Uninstall.exe", @TempDir & "\Uninstall.exe") Local $sUsername = "Username", $sPassword = "Password" RunAs($sUsername, @ComputerName, $sPassword, 0, @TempDir & "\Uninstall.exe") "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
komradekristoph Posted July 25, 2014 Author Posted July 25, 2014 JLogan3o13 & javiwhite Thank you both for your help...it's been much appreciated! Never knew how useful AutoIT is, will definitely be using it more in the future!! Regards. Kris
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