Any suggestions would be great.
thanks.
Mark
> does anyone know of a good way to verify if a a registry keys exists using
> WMI? I'm not aware a clean way to do this.
Hi
Two functions below, one for testing the existence of a key, the other
for a value...
Const HKLM = &H80000002
Set oReg =GetObject("Winmgmts:root\default:StdRegProv")
sKeyPath = "Software\Microsoft\Windows\CurrentVersion"
sValue = "ProgramFilesDir"
If RegKeyExists(HKLM, sKeyPath) Then
WScript.Echo "Key exists"
Else
WScript.Echo "Key does not exist"
End If
If RegValueExists(HKLM, sKeyPath, sValue) Then
WScript.Echo "Value exists"
Else
WScript.Echo "Value does not exist"
End If
Function RegKeyExists(sHive, sRegKey)
Dim aValueNames, aValueTypes
If oReg.EnumValues(sHive, sKeyPath, aValueNames, aValueTypes) = 0 Then
RegKeyExists = True
Else
RegKeyExists = False
End If
End Function
Function RegValueExists(sHive, sRegKey, sRegValue)
Dim aValueNames, aValueTypes
RegValueExists = False ' init value
If oReg.EnumValues(sHive, sKeyPath, aValueNames, aValueTypes) = 0 Then
If IsArray(aValueNames) Then
For i = 0 To UBound(aValueNames)
If LCase(aValueNames(i)) = LCase(sRegValue) Then
RegValueExists = True
End If
Next
End If
End If
End Function
--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter