Suche in der Registry mit VBScript

Hallo!

Ich möchte mit einem VBScript herausfinden, ob z.B. das Service Pack 1 für Visual Basic 2005 Express installiert ist. Dieses Service Pack hat die Nummer KB926747. Leider trägt es sich unter „HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall“ mit scheinbar zufälligen Nameserweiterungen ein, z.B.: „KB926747.T2_17ToU291_17“.

Wenn ich nun nach der KB926747 in der Registry suchen, finde ich natürlich nichts. Hier mal mein kleines Beispiel:

*****
Dim WshShell,
Set WshShell = WScript.CreateObject(„WScript.Shell“)
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\KB926747\DisplayName“)
If Key „“ Then Wscript.Echo Key
*****

Wie kann ich also einen kompletten Registry Schlüssel samt Unterschlüssel nach einem String durchsuchen?

Danke
Ottifant

Jein
Hallo Ottifant,

mit VBScript geht das meines Wissens nicht. Du kannst aber von VBS aus CMD-Kommandos ausführen und die Ergebnisse auslesen. Darum empfehle ich Dir den CMD-Befehl „REG“ bzw. „REG QUERY“. Mehr darüber erfährst Du, wenn Du in der Eingabeaufforderung

REG /?

oder

REG QUERY /?

eingibst.

Schöne Grüße,

Mohamed.

REG QUERY /?

Danke für den Tip!
Aber ich habe Probleme mit der Syntax. :frowning:

folgende Zeile habe ich in mein Skript eingebaut:
Output = objShell.Run("%COMSPEC% REG QUERY HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall | find /i „KB926606“, , True")

Bei der Ausführung bekomme ich vom WSH einen Kompilierungsfehler. Er kommt anscheinend mit den Anführungszeichen vom FIND nicht zurecht.

Den FIND muß ich aber benutzen, weil die Suche mit REG QUERY nicht sehr komfortabel ist (man kann nicht nach Teilen eines Schlüsselnamen suchen ).

Weiß jemand die korrekte Syntax?

Strings
Hallo Ottifant,

Anführungszeichen, die zum Inhalt des Strings selbst gehören, müssen mit doppeltem Anführungszeichen dargestellt werden:

x = "Man nannte ihn ""Nobody""."

Aber dennoch gehe ich davon aus, dass FIND nicht nötig ist, da du den Rückgabestring mit VBS-Funktionen durchsuchen kannst.

Schöne Grüße,

Mohamed.

Aber dennoch gehe ich davon aus, dass FIND nicht nötig ist, da
du den Rückgabestring mit VBS-Funktionen durchsuchen kannst.

Du hast natürlich Recht! Nur bin ich in VBS ein absoluter Neuling und habe meine Schwierigkeiten mit der Syntax und der spärlichen Dokumentation dafür.

Aber ich habe mich durchgekämpft und bin mit dem Ergebnis ganz zufrieden. Ist vielleicht nicht der sauberste Code, aber tut was er soll! Nämlich die Version eines installierten MS Visual Studio anzeigen.

Vielen Dank nochmal für Deine Hinweise!
Ottchen

hier das komplette Skript für Interessierte :wink:
****************************************************************
Dim WshShell, Key, Output
'run the next line with „WSCRIPT.“ in a CommandWindow or without „WSCRIPT.“ at BgInfo
Set WshShell = WScript.CreateObject(„WScript.Shell“)
'Set WshShell = CreateObject(„WScript.Shell“)

'set registry hive
Const HKEY_LOCAL_MACHINE = &H80000002
Const ForReading = 1
'set registry key
strKeyPath = „SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall“
'from local computer
strComputer = „.“

On Error Resume Next

'function to search the registry - call it with the pattern as parameter!
Function RegSearch(strPattern)
'create search pattern
Set objRegEx = CreateObject(„VBScript.RegExp“)
objRegEx.Pattern = strPattern
'check the given parameter
'Wscript.Echo „Search Pattern is „““ & objRegEx.Pattern & „“""
Set objReg=GetObject(„winmgmts:{impersonationLevel=impersonate}!\“ & strComputer & „\root\default:StdRegProv“)
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
'loop to compare each reg entry with the search pattern
For Each Subkey in arrSubKeys
Set colMatches = objRegEx.Execute(Subkey)
If colMatches.Count > 0 Then
For Each strMatch in colMatches
'check all hits
'Wscript.Echo Subkey
RegSearch = Subkey
Next
End If
Next
end function

'********* Generation 1998 *********

'Visual Studio 6 Standard
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Visual Studio 6.0 Standard Edition\DisplayName“)
If Key „“ Then
If Output „“ Then Output = Output & vbCrLf
Output = Output & Key
End If

'tested OK
'Visual Studio 6 Enterprise
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Visual Studio 6.0 Enterprise Edition\DisplayName“)
If Key „“ Then
If Output „“ Then Output = Output & vbCrLf
Output = Output & Key
End If

'********* Generation 2003 *********

'tested OK
'Visual Studio .NET 2003 Professional English
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Visual Studio .NET Professional 2003 - English\DisplayName“)
If Key „“ Then
If Output „“ Then Output = Output & vbCrLf
Output = Output & Key
End If

'tested OK
'Visual Studio .NET 2003 Professional German
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Visual Studio .NET Professional 2003 - German\DisplayName“)
If Key „“ Then
If Output „“ Then Output = Output & vbCrLf
Output = Output & Key
End If

'tested OK
'Visual Studio .NET 2003 Service Pack 1
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\7.1\InstalledProducts\S918007\ProductDetails“)
If Key „“ Then
Output = Output & " SP1"
End If

'********* Generation 2005 *********

'tested OK
'Visual Studio 2005 Professional Englisch
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Visual Studio 2005 Professional Edition - ENU\DisplayName“)
If Key „“ Then
If Output „“ Then Output = Output & vbCrLf
Output = Output & Key
End If

'tested OK
'Visual Studio 2005 Professional German
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Visual Studio 2005 Professional Edition - DEU\DisplayName“)
If Key „“ Then
If Output „“ Then Output = Output & vbCrLf
Output = Output & Key
End If

'tested OK
'Visual Studio 2005 Standard Englisch
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Visual Studio 2005 Standard Edition - ENU\DisplayName“)
If Key „“ Then
If Output „“ Then Output = Output & vbCrLf
Output = Output & Key
End If

'tested OK
'Visual Studio 2005 Standard German
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Visual Studio 2005 Standard Edition - DEU\DisplayName“)
If Key „“ Then
If Output „“ Then Output = Output & vbCrLf
Output = Output & Key
End If

'Visual Studio 2005 Service Pack 1 ENU
'call function RegSearch() with search pattern as parameter
Check = RegSearch(„KB926601“)
If Check „“ Then
Output = Output & " with SP1"
End If

'Visual Studio 2005 Service Pack 1 DEU
'call function RegSearch() with search pattern as parameter
Check = RegSearch(„KB926606“)
If Check „“ Then
Output = Output & " mit SP1"
End If

'********* Generation 2005 Express *********

'tested OK
'Visual Basic 2005 Express Englisch
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Visual Basic 2005 Express Edition - ENU\DisplayName“)
If Key „“ Then
If Output „“ Then Output = Output & vbCrLf
Output = Output & Key
End If

'tested OK
'Visual Basic 2005 Express German
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Visual Basic 2005 Express Edition - DEU\DisplayName“)
If Key „“ Then
If Output „“ Then Output = Output & vbCrLf
Output = Output & Key
End If

'Visual Basic 2005 Express Service Pack 1
Check = RegSearch(„KB926747“)
If Check „“ Then
Output = Output & " SP1"
End If

'tested OK
'Visual C# 2005 Express Englisch
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Visual C# 2005 Express Edition - ENU\DisplayName“)
If Key „“ Then
If Output „“ Then Output = Output & vbCrLf
Output = Output & Key
End If

'tested OK
'Visual C# 2005 Express German
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Visual C# 2005 Express Edition - DEU\DisplayName“)
If Key „“ Then
If Output „“ Then Output = Output & vbCrLf
Output = Output & Key
End If

'Visual C# 2005 Express Service Pack 1
Check = RegSearch(„KB926749“)
If Check „“ Then
Output = Output & " SP1"
End If

'tested OK
'Visual C++ 2005 Express Englisch
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Visual C++ 2005 Express Edition - ENU\DisplayName“)
If Key „“ Then
If Output „“ Then Output = Output & vbCrLf
Output = Output & Key
End If

'tested OK
'Visual C++ 2005 Express German
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Visual C++ 2005 Express Edition - DEU\DisplayName“)
If Key „“ Then
If Output „“ Then Output = Output & vbCrLf
Output = Output & Key
End If

'Visual C++ 2005 Express Service Pack 1
Check = RegSearch(„KB926748“)
If Check „“ Then
Output = Output & " SP1"
End If

'tested OK
'Visual J# 2005 Express Englisch
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Visual J# 2005 Express Edition - ENU\DisplayName“)
If Key „“ Then
If Output „“ Then Output = Output & vbCrLf
Output = Output & Key
End If

'Visual J# 2005 Express German is not available

'Visual J# 2005 Express Service Pack 1
Check = RegSearch(„KB926750“)
If Check „“ Then
Output = Output & " SP1"
End If

'tested OK
'Visual Web Developer 2005 Express Englisch
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Visual Web Developer 2005 Express Edition - ENU\DisplayName“)
If Key „“ Then
If Output „“ Then Output = Output & vbCrLf
Output = Output & Key
End If

'tested OK
'Visual Web Developer 2005 Express German
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Visual Web Developer 2005 Express Edition - DEU\DisplayName“)
If Key „“ Then
If Output „“ Then Output = Output & vbCrLf
Output = Output & Key
End If

'Visual Web Developer 2005 Express Service Pack 1
Check = RegSearch(„KB926751“)
If Check „“ Then
Output = Output & " SP1"
End If

'********* Generation 2008 *********

'tested OK
'Visual Studio 2008 Professional Englisch
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Visual Studio 2008 Professional Edition - ENU\DisplayName“)
If Key „“ Then
If Output „“ Then Output = Output & vbCrLf
Output = Output & Key
End If

'tested OK
'Visual Studio 2008 Professional German
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Visual Studio 2008 Professional Edition - DEU\DisplayName“)
If Key „“ Then
If Output „“ Then Output = Output & vbCrLf
Output = Output & Key
End If

'tested OK
'Visual Studio 2008 Standard Englisch
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Visual Studio 2008 Standard Edition - ENU\DisplayName“)
If Key „“ Then
If Output „“ Then Output = Output & vbCrLf
Output = Output & Key
End If

'tested OK
'Visual Studio 2008 Standard German
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Visual Studio 2008 Standard Edition - DEU\DisplayName“)
If Key „“ Then
If Output „“ Then Output = Output & vbCrLf
Output = Output & Key
End If

'********* Generation 2008 Express *********

'tested OK
'Visual Basic 2008 Express Englisch
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Visual Basic 2008 Express Edition - ENU\DisplayName“)
If Key „“ Then
If Output „“ Then Output = Output & vbCrLf
Output = Output & Key
End If

'tested OK
'Visual Basic 2008 Express German
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Visual Basic 2008 Express Edition - DEU\DisplayName“)
If Key „“ Then
If Output „“ Then Output = Output & vbCrLf
Output = Output & Key
End If

'tested OK
'Visual C# 2008 Express Englisch
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Visual C# 2008 Express Edition - ENU\DisplayName“)
If Key „“ Then
If Output „“ Then Output = Output & vbCrLf
Output = Output & Key
End If

'tested OK
'Visual C# 2008 Express German
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Visual C# 2008 Express Edition - DEU\DisplayName“)
If Key „“ Then
If Output „“ Then Output = Output & vbCrLf
Output = Output & Key
End If

'tested OK
'Visual C++ 2008 Express Englisch
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Visual C++ 2008 Express Edition - ENU\DisplayName“)
If Key „“ Then
If Output „“ Then Output = Output & vbCrLf
Output = Output & Key
End If

'tested OK
'Visual C++ 2008 Express German
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Visual C++ 2008 Express Edition - DEU\DisplayName“)
If Key „“ Then
If Output „“ Then Output = Output & vbCrLf
Output = Output & Key
End If

'tested OK
'Visual Web Developer 2008 Express Englisch
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Visual Web Developer 2008 Express Edition - ENU\DisplayName“)
If Key „“ Then
If Output „“ Then Output = Output & vbCrLf
Output = Output & Key
End If

'tested OK
'Visual Web Developer 2008 Express German
Key = „“
Key = WshShell.RegRead(„HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Visual Web Developer 2008 Express Edition - DEU\DisplayName“)
If Key „“ Then
If Output „“ Then Output = Output & vbCrLf
Output = Output & Key
End If

'********* Summary *********

'check if no VisualStudio is installed
If Output = „“ Then Output = „none“

'remove trailing spaces
Output = Trim(Output)

'run the next line with „WSCRIPT.“ in a CommandWindow or without „WSCRIPT.“ at BgInfo
Wscript.Echo Output
'Echo Output
****************************************************************

Hallo!

Alternativ könnte man auf die Datei-Info einer (wichtigen) Datei des „Service Pack 1 für Visual Basic 2005 Express“ prüfen - mit:

fso.GetFileVersion( WichtigeDatei )

(aus http://dieseyer.de/scr-html/shell32dllversion.html)

[Bei dieser Antwort wurde das Vollzitat nachträglich automatisiert entfernt]