CheckRegistryKey – Return True if a Registry key exists

Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" _    (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, _    ByVal samDesired As Long, phkResult As Long) As LongPrivate Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As _    LongConst KEY_READ = &H20019  ' ((READ_CONTROL Or KEY_QUERY_VALUE Or                           ' KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not                           ' SYNCHRONIZE))' Return True if a Registry key existsFunction CheckRegistryKey(ByVal hKey As Long, ByVal KeyName As String) As _    Boolean    Dim handle As Long    ' Try to open the key    If RegOpenKeyEx(hKey, KeyName, 0, KEY_READ, handle) = 0 Then        ' The key exists        CheckRegistryKey = True        ' Close it before exiting        RegCloseKey handle    End IfEnd Function

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: