Zinthose Posted April 3, 2009 Posted April 3, 2009 (edited) It's been almost a year since I last attempted to create this bit of code and I have learned allot and have rewritten the code that I originally posted here: SlowInfoCache w/ AutoIt3, EXAMPLE: Parsing the SlowInfoCache Registry.Thus far, This has only been tested on Windows XP and Windows XP x64.The new solution is far more elegant. Enjoy.expandcollapse popup#Region - Add & Remove Programs Cache #Include 'Date.au3'; <== Required by _ARPCache() Function ;################################################################################################### ;## _ARPCache(String $ARP_KeyName) ;## $ARP_KeyName - Name of the Registry Key to scan. Available from: ;## HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Management\ARPCache\* ;## ;## Returns Array[5] ;## [0] Boolean HasName - True if the application is listed in Add & Remove Programs ;## [1] Long InstallSize - Numeric value representing the size in bytes of the install ;## [2] String LastUsed - Date of last detected time the application was used ;## [3] Integer Frequency - Number of times and application was used in the past 30 days. ;## [4] String Name - Path to executable that last triggered an update ;## ;################################################################################################### Func _ARPCache($ARP_KeyName) Local $RegKey = "HKLM%s\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Management\\ARPCache\\%s" Local $RegName = "SlowInfoCache" Local $KeyVal = "" Local $tagARPCACHE = "dword cbSize;ubyte HasName;uint64 InstallSize;dword LastUsed[2];int Frequency;wchar Name[261]" Local $RawData = DllStructCreate("byte Data[552]") Local $LastUsed = DllStructCreate("dword Lo;dword Hi") Local $SlowInfoCache Local $Array[5] ;## Validate Parameters If Not IsString($ARP_KeyName) Then Return SetError(1, 0, 0) ;## Read Value from the Registry If @OSArch <> "X86" And Not @AutoItX64 Then $KeyVal = "64" $RegKey = StringFormat($RegKey, $KeyVal, $ARP_KeyName) $KeyVal = RegRead($RegKey, $RegName) If @error Then Return SetError(2, 0, 0) ;## Parse the cryptic Registry value to something more readable DllStructSetData($RawData, 1, $KeyVal) If @error Then Return SetError(3, 0, 0) $TSlowInfoCache = DllStructCreate($tagARPCACHE, DllStructGetPtr($RawData)) If @error Then Return SetError(4, 0, 0) DllStructSetData($LastUsed, "Lo", DllStructGetData($TSlowInfoCache, "LastUsed", 1)) DllStructSetData($LastUsed, "Hi", DllStructGetData($TSlowInfoCache, "LastUsed", 2)) If @error Then Return SetError(5, 0, 0) $Array[0] = DllStructGetData($TSlowInfoCache, "HasName") = 1; <== Convert to Boolean $Array[1] = DllStructGetData($TSlowInfoCache, "InstallSize") $Array[2] = _Date_Time_FileTimeToStr($LastUsed) $Array[3] = DllStructGetData($TSlowInfoCache, "Frequency") $Array[4] = DllStructGetData($TSlowInfoCache, "Name") ;## Return Array of Values Return $Array EndFunc #EndRegion - Add & Remove Programs Cache #Region - Example #Include 'Array.au3' #include 'ComboConstants.au3' #include 'GUIConstantsEx.au3' #include 'ListViewConstants.au3' #include 'StaticConstants.au3' #include 'WindowsConstants.au3' #include 'GuiListView.au3' Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= $guiExample = GUICreate("Add & Remove Programs Cache - Example", 633, 225, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "guiExampleClose") GUICtrlCreateLabel("ARP &KeyName:", 12, 12, 84, 17) $cmbARP_KeyNames = GUICtrlCreateCombo("", 12, 30, 607, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL,$CBS_SORT)) GUICtrlSetOnEvent(-1, "cmbARP_KeyNamesChange") $lstARP_Data = GUICtrlCreateListView("index|Caption|Value", 12, 60, 607, 151) GUICtrlSendMsg(-1, 0x101E, 0, 20) GUICtrlSendMsg(-1, 0x101E, 1, 100) GUICtrlSendMsg(-1, 0x101E, 2, 483) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### _AddKeyNames() While 1 Sleep(100) WEnd Func cmbARP_KeyNamesChange() Local $Format = "%s|%s|%s" Local $ARP_KeyName = GUICtrlRead($cmbARP_KeyNames) If $ARP_KeyName = "" Then Return ;## Get the ARPCache Data $ARP_Array = _ARPCache($ARP_KeyName) If @error Then Exit @error ;## Display the ARPCache Values from the selected KeyName _GUICtrlListView_DeleteAllItems($lstARP_Data) GUICtrlCreateListViewItem(StringFormat($Format, 0, "HasName", $ARP_Array[0]), $lstARP_Data) GUICtrlCreateListViewItem(StringFormat($Format, 1, "InstallSize", $ARP_Array[1]), $lstARP_Data) GUICtrlCreateListViewItem(StringFormat($Format, 2, "LastUsed", $ARP_Array[2]), $lstARP_Data) GUICtrlCreateListViewItem(StringFormat($Format, 3, "Frequency", $ARP_Array[3]), $lstARP_Data) GUICtrlCreateListViewItem(StringFormat($Format, 4, "Name", $ARP_Array[4]), $lstARP_Data) EndFunc Func guiExampleClose() Exit EndFunc Func _AddKeyNames() Local $RegKey = "HKLM%s\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Management\\ARPCache" Local $KeyVal, $RegValue, $i = 1, $Data = "" ;## Read KeyNames from the Registry If @OSArch <> "X86" And Not @AutoItX64 Then $KeyVal = "64" $RegKey = StringFormat($RegKey, $KeyVal) SplashTextOn("Loading List of Add Remove Programs", "Please wait...", 300, 50) While True $RegValue = RegEnumKey($RegKey, $i) If @error Then ExitLoop If $Data <> "" Then $Data &= "|" $Data &= $RegValue $i += 1 WEnd SplashOff() ;## Add List of KeyNames to the ComboBox GUICtrlSetData($cmbARP_KeyNames, $Data) EndFunc #EndRegion - ExampleUpdated to fix a bug with 64bit support and adjusted formatting. Edited February 17, 2010 by Zinthose --- TTFN
Zinthose Posted February 16, 2010 Author Posted February 16, 2010 Code updated to address a bug with the 64bit implementation. For the Altiris junkies out there. I'm working of developing an NS 7 dataclass/collector. Allot of this data can be acquired using App Metering , but this method allows for another data source for comparisons. --- TTFN
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