Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Need some help with an "installed programs" script...

$
0
0
This question is a bit of a follow-up from this post:  http://www.autoitscript.com/forum/topic/123146-list-installed-programs-and-system-information/

I used the code provided by boththose (and credits to ripdad) to try and mold the script into doing what I am trying to achieve, but I've run into a snag of sorts, and I haven't been able to puzzle it out.

Before I start, let me say I haven't coded much of anything since 2004/2005...so to say I'm rusty...that would be very polite...

I'm trying to inventory the list of installed programs, print out a subset of programs applicable to the software I'm trying to find, and then provide a single-button-click to install any software that needs to be updated.  The program works, all of the relevant messages are displayed and it seems like it displays the proper software in the list and runs the proper .exe at the right time.  Everything looks good...

On my test PC, I ran the script .exe, did a right-click Uninstall on the Java software.  Seems to have run fine.  Executing the script again shows no listing of Java.  I run the Java installer from the button at the bottom (64-bit) and the installer runs fine.  I see Java installed in the Control Panel.  I actually see the Java key in the Uninstall registry keys.  However, the script no longer lists Java as an installed program.

Any insight would be appreciated...I've been staring at boththose and ripdad's code for a while, but I can't find the issue...


[ autoit ]         
#include Opt("TrayAutoPause", 0) Opt('GUIOnEventMode', 1) Opt('GUICloseOnEsc' , 1) Global $i ;Filling an array with software names I want to check against the installed software listing array. Global $m[2] = ["java", "openvpn"] Global $n Local $sSft Global $sGui = GUICreate('Currently Installed Software for ' & @OSVersion & ' ' & @OSArch, 810, 650, -1, -1) Global $sLvw = GUICtrlCreateListView('#|Installed Software|Display Version|Publisher|Uninstall String', 5, 5, 800, 600) ;Function call to create a C:\temp folder and copy the .exe's to it for the software to be updated. _FileList() _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, 175) 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') ;Creating buttons on the GUI to call the .exe's to install software from C:\temp. Local $java32 = GUICtrlCreateButton(' Java Update (32bit) ', 5, 615 ) GUICtrlSetOnEvent($java32, '_JavaUpdate32') Local $java64 = GUICtrlCreateButton(' Java Update (64bit) ',175, 615) GUICtrlSetOnEvent($java64, '_JavaUpdate64') Local $VPN = GUICtrlCreateButton(' OpenVPN 2.2 ',550, 615) GUICtrlSetOnEvent($VPN, '_OpenVPN') ;Function call to check Windows Registry for Windows Updates enabled or not. _WUpdateRegRead() 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 RunWait ($proc[5]) exit EndFunc ; Func _ComputerGetSoftware(ByRef $aSoftwareInfo) Local Const $UnInstKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" Local $i = 1 Local $n = 0 Dim $aSoftwareInfo[1][4] $input = inputbox ("Which Software" , "You are running " & @OSVersion & " " & @OSARCH & @CRLF & @CRLF & "Which Software would you like to view, ALL or Some?", 'Some') 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,0,1) Else IF $input = 'Some' Then ;Looping the array from above, checking for "java" or "openvpn" in the list of installed programs. For $n = 0 to 2 - 1 For $j = 1 To 500 $AppKey = RegEnumKey($UnInstKey, $j) If @error <> 0 Then Exitloop $Reg = RegRead($UnInstKey & "\" & $AppKey, "DisplayName") $string = stringinstr($Reg, $m[$n]) 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 Next $aSoftwareInfo[0][0] = UBound($aSoftwareInfo, 1) - 1 If $aSoftwareInfo[0][0] < 1 Then SetError(1, 1, 0) Return _ArraySort($aSoftwareInfo,0,1) Endif Endif EndFunc ; ;Function to copy .exe installers to the local C:\temp of the PC the script is executing on. Func _FileList() DirCreate("C:\temp\") FileInstall('C:\Users\me\Desktop\Installers\jre-6u39-windows-x64.exe', 'C:\temp\', 1) FileInstall('C:\Users\me\Desktop\Installers\jre-6u39-windows-i586.exe', 'C:\temp\', 1) FileInstall('C:\Users\me\Desktop\Installers\openvpn-setup-final.exe', 'C:\temp\', 1) EndFunc ; ;Start 32-bit Java install Func _JavaUpdate32() Run("C:\temp\jre-6u39-windows-i586.exe") EndFunc ; ;Start 64-bit Java install Func _JavaUpdate64() Run("C:\temp\jre-6u39-windows-x64.exe") EndFunc ; ;Start OpenVPN install Func _OpenVPN() Run("C:\temp\openvpn-setup-final.exe") EndFunc ; ;Read registry to see if WUpdate is enabled, if not, display a button click to run the relevant function to add registry entries to enable WUpdate. Func _WUpdateRegRead() Local $wupdate = RegRead("HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\WindowsUpdate\AU", "NoAutoUpdate") If $wupdate <> 0 Then If @OSArch = 'x64' Then Local $w7updategui64 = GUICtrlCreateButton(' Enable Windows Updates ', 50, 615 ) GUICtrlSetOnEvent($w7updategui64, '_W7UpdateRegWrite64') ElseIf @OSArch <> 'x64' Then Local $w7updategui32 = GUICtrlCreateButton(' Enable Windows Updates ', 300, 615 ) GUICtrlSetOnEvent($w7updategui32, '_W7UpdateregWrite32') EndIf EndIf EndFunc ; ;Placeholder for registry entries to enable WUpdate for 64-bit Win 7 Func _W7UpdateRegWrite64() MsgBox(4096, "Enabling Windows Updates", "Applying Windows Update Policies for Windows 7 (64-bit)", 5) EndFunc ; ;Placeholder for registry entries to enable WUpdate for 32-bit Win 7 Func _W7UpdateRegWrite32() MsgBox(4096, "Enabling Windows Updates", "Applying Windows Update Policies for Windows 7 (32-bit)", 5) EndFunc ;

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>