Hi guys, need help here. I would like to check the registry key is exist for this code:

Sub main()
        Dim regKey As Object = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{D75F38ED-E49A-48F3-9B72-D4BC5FE73B44}", True)

        ' Check if it exists
        If regKey Is Nothing Then
            MsgBox("Registry key does not exist!")
        Else

            MsgBox("Registry key is exists.")

        End If
    End Sub

It telling registry key does not exist, but when i remove "{D75F38ED-E49A-48F3-9B72-D4BC5FE73B44}", it managed to find the registry key. So Im suspecting it couldn't detect special symbol like parentheses "{" & "}" ?

Anyone could help me to figure out?

Dani AI

Generated

Braces are not the cause — Windows registry supports GUID-style subkey names. As noted, opening read-only (False) avoids the common SecurityException you get when requesting write access. The usual reasons your code sometimes reports "not found" are: registry redirection on 64-bit Windows (Wow6432Node), permission/UAC differences, or an accidental non-printing character in the GUID string copied into your code.

Quick checklist to narrow it down:

  1. Open Regedit and search HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall for the exact subkey; note whether it lives under Wow6432Node.
  2. Copy the subkey name directly from Regedit to avoid hidden/Unicode characters.
  3. If your app is 32-bit on a 64-bit OS, explicitly read the 64-bit view instead of relying on process redirection. Example (VB.NET, .NET 4+):
' Explicitly read the 64-bit hive
Imports Microsoft.Win32

Dim baseKey As RegistryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)
Dim regKey As RegistryKey = baseKey.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{your-GUID-here}", False)

If regKey Is Nothing Then
    ' Not present in the 64-bit view
End If

If you must write, request writable True but wrap in try/catch for SecurityException/UnauthorizedAccessException. Alternatively run the code as x64 or set AnyCPU with "Prefer 32-bit" unchecked so the process sees the 64-bit keys. If it suddenly worked for , it was probably a typo, a different process architecture, or a transient permission difference.

Recommended Answers

All 4 Replies

I did this

Dim key As String = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{002568CE-7595-46A3-A1C1-53F41A4ADC34}"
Dim regKey As RegistryKey = Registry.LocalMachine.OpenSubKey(key, False)

If regKey Is Nothing Then
    MsgBox("Registry key does not exist!")
Else
    MsgBox("Registry key exists.")
End If

on my system (Windows 7 Pro) and it worked just fine. Note that I used False as the second parameter to avoid a System Security Exception.

Hi Jim, thanks for your reply.. but it still not work for me.. It only work when I replace the "{002568CE-7595-46A3-A1C1-53F41A4ADC34}" to "AddressBook", somewhat a proper english.. :(

I don't have that particular key so I can't run the same test, however, my example does show that the brace brackets are not the cause of the problem.

Hi Jim, I don't know what happened, but it just worked now. haha. Thanks a lot, man.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.