Windows Server 2008 でレジストリ エントリを読み取ろうとしているときに問題が発生しました。不可解なことは、コードが 2008 であるが R2 である別のサーバーで動作することです。確認したところ、レジストリ エントリが適切に配置されており、管理者としてプログラムを実行しました。以下はコードサンプルです。Registry.LocalMachine.OpenSubKey によって返されたレジストリ キーが null です。これは 64 ビット アプリケーションです
string strPath = "";
try
{
//The registry key:
//SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\SnmpClient.exe
using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(strKey))
{
try
{
//InstallDirectory
if (!(rk.GetValue(strValue) == null))
{
strPath += rk.GetValue(strValue).ToString();
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return strPath;