Powered By Blogger

Thursday, August 1, 2013

VBS to check the existence of a Key in Registry

We can use simple vbscript for checking the existence of a Key in Registry.
Here is the sample code:


IsKeyExists("KeyName")

Function IsKeyExists(KeyName)

  Const HKCR = &H80000000 'HKEY_CLASSES_ROOT
  Const HKCU = &H80000001 'HKEY_CURRENT_USER
  Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
  Const HKUS = &H80000003 'HKEY_USERS
  Const HKCC = &H80000005 'HKEY_CURRENT_CONFIG

  Dim oReg: Set oReg = GetObject("winmgmts:!root/default:StdRegProv")
  KeyPath = "SOFTWARE\Microsoft\Windows\" & KeyName
  If oReg.EnumKey(HKLM, KeyPath, arrSubKeys) = 0 Then
    IsProductInstalled = True
  Else
KeyPath = "SOFTWARE\WoW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" & GUID
If oReg.EnumKey(HKLM, KeyPath, arrSubKeys) = 0 Then
MsgBox("Key Exists")
Else
MsgBox("Key is not exists")
End If
  End If
End Function

No comments: