我需要检查注册表中的值。该应用程序(Cisco VPN)是一个32位应用程序,因此在64位操作系统上安装时使用Wow6432Node。
选择使用哪个字符串的最佳方法是什么?检查操作系统是否为x64,如果第一次失败,尝试读取一个,然后另一个读取?或者有更好的方法吗?
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"
使用.net 4.0框架?:
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
答案 0 :(得分:1)
您只需要检查代码是否以64位模式运行。这很简单:
Dim key As String
If IntPtr.Size = 8 Then key = keyName64 Else key = keyName32