' Collection of code snippets by Arne Vajhøj 
' (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_CONFIG = &H80000005
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003

Public Const KEY_QUERY_VALUE = 1

Public 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 Long
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long

Private Function RegKeyExists(hKey As Long, sKeyPath As String) As Boolean
Dim lResult As Long
Dim hSubkey As Long
lResult = RegOpenKeyEx(hKey, sKeyPath, 0, KEY_QUERY_VALUE, hSubkey)
If hSubkey <> 0 Then
   RegKeyExists = True
   RegCloseKey hKey
Else
    RegKeyExists = False
End If
End Function

Function TestRegKeyExists()
    MsgBox ("O 9 = " & CStr(RegKeyExists(HKEY_CURRENT_USER, "Software\Microsoft\Office\9.0\Outlook")))
    MsgBox ("O 10 = " & CStr(RegKeyExists(HKEY_CURRENT_USER, "Software\Microsoft\Office\10.0\Outlook")))
    MsgBox ("O 11 = " & CStr(RegKeyExists(HKEY_CURRENT_USER, "Software\Microsoft\Office\11.0\Outlook")))
    MsgBox ("O 12 = " & CStr(RegKeyExists(HKEY_CURRENT_USER, "Software\Microsoft\Office\12.0\Outlook")))
    MsgBox ("O 13 = " & CStr(RegKeyExists(HKEY_CURRENT_USER, "Software\Microsoft\Office\13.0\Outlook")))
    MsgBox ("OE 4 = " & CStr(RegKeyExists(HKEY_CURRENT_USER, "Software\Microsoft\Outlook Express\4.0")))
    MsgBox ("OE 5 = " & CStr(RegKeyExists(HKEY_CURRENT_USER, "Software\Microsoft\Outlook Express\5.0")))
    MsgBox ("OE 6 = " & CStr(RegKeyExists(HKEY_CURRENT_USER, "Software\Microsoft\Outlook Express\6.0")))
End Function
