Reputation: 1397
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
Upvotes: 0
Views: 2228
Reputation: 942255
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
Upvotes: 1