Elencare gli applicativi installati #2
In questo post Elencare gli applicativi installati tramite WMI avevo proposto una possibile soluzione basata su WMI per leggere l’elenco degli applicativi installati sul computer locale o remoto.
Un’altra possibile soluzione è quella di leggere il registry analizzando le sottochiavi in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, questa soluzione permette di filtrare l’elenco ottenuto per escludere i componenti di sistema (che hanno la subkey SystemComponent=1), i componenti legati ad altri componenti (che hanno la subkey ParentKeyName).
Di seguito un esempio di script:
Option Explicit
Const HKLM = &H80000002
Dim ComputerName
ComputerName = Inputbox(“Enter the computer name (Default .=local computer):”, “Get Applications List”, “.”)
If ComputerName = “” Then
ComputerName=”.”
End If
‘*** Apertura RegistryLettura Applicazioni installate
Dim Reg
Set Reg=GetObject( “winmgmts:{impersonationLevel=impersonate}!\\” & _
ComputerName & “\root\default:StdRegProv”)
‘*** Creazione File
Dim fso, file, filename
Set fso = CreateObject(“Scripting.FileSystemObject”)
filename = “Applications.txt”
If ComputerName = “.” Then
filename = “LocalComputer-” & filename
Else
filename = ComputerName & “-” & filename
End If
Set file = fso.CreateTextFile( filename, True)
‘*** Lettura Applicazioni installate
Dim KeyPath, SubKeys, SubKey
KeyPath=”SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\”
Reg.EnumKey HKLM, KeyPath, SubKeys
Dim result, value, line
For Each SubKey In SubKeys
result = Reg.GetStringValue(HKLM, KeyPath & subKey, “ReleaseType”, value)
If result <> 0 Or (value <> “Security Update” And value <> “Update” And value <> “Hotfix”) Then
If Reg.GetStringValue(HKLM, KeyPath & subKey, “ParentKeyName”, value) <> 0 And _
(Reg.GetDWORDValue(HKLM, KeyPath & subKey, “SystemComponent”, value) <> 0 Or Value <> 1) Then
result = Reg.GetStringValue(HKLM, KeyPath & subKey, “DisplayName”, value)
If result <> 0 Then
result = Reg.GetStringValue(HKLM, KeyPath & subKey, “QuietDisplayName”, value)
End If
If result = 0 AND NOT Trim(value) = “” Then
line = Trim(value)
result = Reg.GetStringValue(HKLM, KeyPath & subKey, “DisplayVersion”, value)
If result = 0 AND NOT Trim(value) = “” Then
line = line & ” [” & value & “]”
End If
file.WriteLine(line)
End If
End If
End If
Next
Set Reg = Nothing
Set SubKeys = Nothing
Set SubKey = Nothing
‘*** Chiusura File
file.Close
Set file = Nothing
‘*** Apertura file con NotePad
Dim WshShell
Set WshShell = WScript.CreateObject( “WScript.Shell” )
WshShell.Run “notepad ” & filename, 3
Set WshShell = Nothing
‘*** Visualizzazione errori
If Err.Number <> 0 Then
MsgBox (“Error # ” & CStr(Err.Number) & ” ” & Err.Description)
End If