DarkDeveloper Posted August 6, 2012 Posted August 6, 2012 This is what I have so far and it works. I wasn't sure if there is a better way to do this. Next step is going to be getting display name and uninstall key. I just wanted to make sure that this is a good way to do the task I am attempting before continuing. Func _uninstallProgram() ;reg to start at Local $regamount = 1 ;get the number of reg While RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", $regamount) $regamount += 1 WEnd ;View error while loop stops on, should be -1 if all reg counted MsgBox(0,"","Array Size: " & $regamount & " Error: " & @error) ;declare array size Local $array[$regamount] ;populate array with list of reg names For $i=0 to $regamount - 1 $array[$i] = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", $i) Next ;check that list populated _ArrayDisplay($array) EndFunc
water Posted August 6, 2012 Posted August 6, 2012 If it works and it is fast enough then you are fine. If it is too slow we can show you how to speed up the code. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Shaggi Posted August 6, 2012 Posted August 6, 2012 You can use _ArrayAdd() so you dont have to enumerate the registry two times. This might be a bit slow for large amounts of data, since the array is resized every time - you could maybe modify the function so the array grows by, say, 1.3 * size when full. Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG
DarkDeveloper Posted August 6, 2012 Author Posted August 6, 2012 There is only 400ish registries per computer. It will grow as more MS updates come but shouldn't be too bad. I do see what you mean Shaggi. I'll tweak with the logic a bit. The first one is just to get the number of registries that exist so I can declare an array size. I'll play around with some other things and if it slows down I will let you know.
Moderators Melba23 Posted August 6, 2012 Moderators Posted August 6, 2012 DarkDeveloper,Take a look at the final script (and following explanation) in the Recursion tutorial in the Wiki - it shows how you can fill an array of unknown size with the minimum number of ReDim calls. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Spiff59 Posted August 6, 2012 Posted August 6, 2012 (edited) Memory is nothing anymore... Just set a large array up front and Redim() it once at the end (which frees the unneeded memory). Throw in an error message in case anyone ever gets close to overflowing the table. #include <Array.au3> Global $iMaxArray = 2500, $array[$iMaxArray + 1] _uninstallProgram() _ArrayDisplay($array) Func _uninstallProgram() For $i = 1 to $iMaxArray $array[$i] = RegEnumKey("HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionUninstall", $i) If @error Then ExitLoop Next If $i > $iMaxArray Then MsgBox(16, "Error", "Maximum table size exceeded.") Exit EndIf $array[0] = $i - 1 ReDim $array[$i] EndFunc Edit: Realistically, you could preset the array to a million elements and it might temporary allocate 20MB of memory until it hits the ReDim() and frees it up. For a wimpy PC with just a measly 1GB that's still only a temporary allocation of 2% of it's memory. Presetting it to anywhere from 1000 to 5000 won't even cause a PC to skip a beat. Edited August 6, 2012 by Spiff59
DarkDeveloper Posted August 6, 2012 Author Posted August 6, 2012 I looked at the recursion page but I don't think it will work since I cannot check for a next registry. However I did do this instead which works and should be more friendly to the part I am doing next. expandcollapse popupFunc _uninstallProgram($programName) Local $array[20] $array[0] = UBound($array,1) MsgBox(0,"",$array[0]) $i = 1 Do $array[$i] = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", $i) If StringCompare ($array[$i], "") = 0 Then MsgBox(0,"","Blank Spot at " & $i) ReDim $array[$i] ExitLoop ElseIf $i = $array[0]-1 Then ReDim $array[UBound($array,1) * 2] $array[0] = UBound($array,1) MsgBox(0,"",$array[0]) EndIf $i += 1 Until $i >= $array[0] ReDim $array[UBound($array,1)] MsgBox(0,"",@error) _ArrayDisplay($array) EndFunc
elektron Posted August 6, 2012 Posted August 6, 2012 Check out my topic (I actually just posted this), that has a #include that you can use for a stack data structure. It'll work pretty well, and after you're done using it, you can just call a function and it will return an array for you to use.
nullschritt Posted August 7, 2012 Posted August 7, 2012 (edited) Idk if this is a stupid idea, but you could just store all the values in a string and separate them with a character, say "|", then use stringsplit? (this way it would automatically size the array, and only have to enum once) Local $regamount = 1 Local $keys = '' do $key = RegEnumKey("HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionUninstall", $regamount) $keys &= $key&'|' $regamount += 1 until @error $array = stringsplit($keys, '|') Edit: working example Edited August 7, 2012 by nullschritt water 1
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