How to check a registry key has no subkeys or values?

I am able to see whether a particular registry key exist or not but not able to get the code for checking whether that particular registry hive is having any subkeys or values.
I need to delete it if the hive is empty.

Can you suggest.

0 Comments   [ + ] Show comments

Answers (1)

Posted by: ur00361883 7 years ago
Black Belt
Got the solution.
This Link is helpful.
' Constants (taken from WinReg.h)'Const HKEY_CLASSES_ROOT   = &H80000000Const HKEY_CURRENT_USER   = &H80000001Const HKEY_LOCAL_MACHINE  = &H80000002Const HKEY_USERS          = &H80000003Const REG_SZ        = 1Const REG_EXPAND_SZ = 2Const REG_BINARY    = 3Const REG_DWORD     = 4Const REG_MULTI_SZ  = 7' Chose computer name, registry tree and key path'strComputer = "." ' Use . for current machinehDefKey = HKEY_CURRENT_USERstrKeyPath = "Software\Adobe"' Connect to registry provider on target machine with current user'Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")' Enum the subkeys of the key path we’ve chosen'oReg.EnumKey hDefKey, strKeyPath, arrSubKeysif UBound(arrSubKeys) = 0 Then Msgbox "No Subkeys"Msgbox UBound(arrSubKeys)For Each strSubkey In arrSubKeyswscript.echo strSubkeyNextoReg.EnumValues hDefKey, strKeyPath, arrValueNames, arrTypesif UBound(arrValueNames) = 0 Then Msgbox "No Values"Msgbox UBound(arrValueNames)For Each strValue In arrValueNameswscript.echo strValueNext

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:


This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ