tags:

views:

15

answers:

1

I need to check a value within the registry. The application (Cisco VPN) is a 32bit app so uses Wow6432Node when installed on 64bit operating systems.

What would be the best method of selecting which string to use? Checking the OS for x64, attempting to read one and then the other if the first fails? Or is there a better method?

Dim keyName64 As String = "HKEY_LOCAL_MACHINE\Software\Wow6432Node\Cisco Systems\VPN Client"
Dim keyName32 As String = "HKEY_LOCAL_MACHINE\Software\Cisco Systems\VPN Client"

Using .net 4.0 framework?:

 Dim registryKey As RegistryKey
    If Environment.Is64BitOperatingSystem = True Then
        registryKey = registryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64)
        Else
        registryKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry32)
        End If
+1  A: 

You only need to check if your code is running in 64-bit mode. That's easy:

Dim key As String
If IntPtr.Size = 8 Then key = keyName64 Else key = keyName32
Hans Passant
I see, I was attempting to use the Is64BitOperatingSystem and RegistryView (as amended above)
madlan
Just use RegistryView.Register32 and the key can always be read as keyName32, regardless of the operating system or the bitness of your program.
Hans Passant