Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. On Error Resume Next
  3.  
  4. ' Declare contstants.
  5. Const HKLM = &H80000002
  6.  
  7. ' Declare variables.
  8. strComputer = "."
  9. strKeyPath  = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
  10. strLogPath = "C:\output.log"
  11.  
  12. ' Set objects
  13. Set oDic = CreateObject("Scripting.Dictionary")
  14.  
  15. 'Rem out the next 2 lines below
  16. 'Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
  17. '    strComputer & "\root\default:StdRegProv")
  18.  
  19. 'Add the next 7 lines below for 64bit registry
  20. Set objCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
  21.       Set objLocator = CreateObject("Wbemscripting.SWbemLocator")
  22.      
  23.       ' Set the registry provider to the 64-bit registry provider    
  24.      objCtx.Add "__ProviderArchitecture", 64
  25.       Set objServices = objLocator.ConnectServer("","root\default","","",,,,objCtx)
  26.       Set oReg = objServices.Get("StdRegProv")
  27. 'MsgBox "Enumerating the subkeys of " & strKeyPath & " in the 64-bit registry..."
  28.  
  29. ' Enumerate subkeys into an array.
  30. oReg.EnumKey HKLM, strKeyPath, arrSubKeys
  31.  
  32. ' Get data from each subkey.
  33. For Each subkey In arrSubKeys
  34.  
  35.   subKeyPath = strKeyPath & "\" & subkey
  36.   oReg.GetStringValue HKLM,subKeyPath,"DisplayName",strValue
  37.   oReg.GetStringValue HKLM,subKeyPath,"UninstallString",strValue2
  38.  
  39. ' Test for non-blank values: we want only non-blank values.
  40.  If strValue <> "" Then
  41.     If strValue2 <> "" Then
  42.  
  43.       ' Add data to dictionary.
  44.      strValue2 = Replace(strValue2,"msiexec.exe /i","msiexec.exe /x")
  45.       oDic.Add strValue, strValue2
  46.  
  47.     End If
  48.   End If
  49.  
  50. Next
  51.  
  52. ' Sort dictionary by key name (the program name).
  53. Set oDic = SortDictionary(oDic, 1)
  54.  
  55. ' Convert dictionary into arrays for processing.
  56. ItemsArray = oDic.Items
  57. KeysArray = oDic.Keys
  58.  
  59. ' Create Log File
  60. Set myFSO = CreateObject("Scripting.FileSystemObject")
  61. Set LogOutput = myFSO.OpenTextFile(strLogPath, 8, True)
  62.  
  63. ' Size the array and step through each element.
  64. intCount = oDic.Count
  65. For i = 0 To intCount
  66.   LogOutput.WriteLine("Program:   " & KeysArray(i))
  67.   LogOutput.WriteLine("Uninstall: " & ItemsArray(i))
  68.   LogOutput.WriteLine(" ")
  69. Next
  70.  
  71. LogOutput.Close
  72.  
  73. ' Declare function to sort dictionary.
  74. Function SortDictionary(objDict, intSort)
  75.   ' Description:
  76.  '   Sorts a dictionary by either key or item
  77.  ' Parameters:
  78.  '   objDict - the dictionary to sort
  79.  '   intSort - the field to sort (1=key, 2=item)
  80.  ' Returns:
  81.  '   A dictionary sorted by intSort
  82.  
  83.     ' declare constants
  84.    Const dictKey  = 1
  85.     Const dictItem = 2
  86.  
  87.     ' declare our variables
  88.    Dim strDict()
  89.     Dim objKey
  90.     Dim strKey,strItem
  91.     Dim X,Y,Z
  92.  
  93.     ' get the dictionary count
  94.    Z = objDict.Count
  95.  
  96.     ' we need more than one item to warrant sorting
  97.    If Z > 1 Then
  98.       ' create an array to store dictionary information
  99.      ReDim strDict(Z,2)
  100.       X = 0
  101.       ' populate the string array
  102.      For Each objKey In objDict
  103.           strDict(X,dictKey)  = CStr(objKey)
  104.           strDict(X,dictItem) = CStr(objDict(objKey))
  105.           X = X + 1
  106.       Next
  107.  
  108.       ' perform a a shell sort of the string array
  109.      For X = 0 To (Z - 2)
  110.         For Y = X To (Z - 1)
  111.           If StrComp(strDict(X,intSort),strDict(Y,intSort),vbTextCompare) > 0 Then
  112.               strKey  = strDict(X,dictKey)
  113.               strItem = strDict(X,dictItem)
  114.               strDict(X,dictKey)  = strDict(Y,dictKey)
  115.               strDict(X,dictItem) = strDict(Y,dictItem)
  116.               strDict(Y,dictKey)  = strKey
  117.               strDict(Y,dictItem) = strItem
  118.           End If
  119.         Next
  120.       Next
  121.  
  122.       ' erase the contents of the dictionary object
  123.      objDict.RemoveAll
  124.  
  125.       ' repopulate the dictionary with the sorted information
  126.      For X = 0 To (Z - 1)
  127.         objDict.Add strDict(X,dictKey), strDict(X,dictItem)
  128.       Next
  129.  
  130.     End If
  131.  
  132. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement