WMI を使用してレジストリ キーを読み取ろうとしています。次のコードを試しましたが、レジストリ キーの値を取得できません。
誰でもこの問題に関して私を助けてくれますか?
ConnectionOptions oConn = new ConnectionOptions();
System.Management.ManagementScope scope = new System.Management.ManagementScope(@"\\" +hostname + @"\root\cimv2", oConn);
scope.Connect();
ManagementClass registry = new ManagementClass(scope, new ManagementPath("StdRegProv"), null);
ManagementBaseObject inParams = registry.GetMethodParameters("GetStringValue");
inParams["sSubKeyName"] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\.NETFramework";
inParams["sValueName"] = "InstallRoot";
ManagementBaseObject outParams = registry.InvokeMethod("GetStringValue", inParams, null);
if (outParams.Properties["sValue"].Value != null)
{
output = outParams.Properties["sValue"].Value.ToString();
}
注: WMI のみを使用してレジストリ キーを読み取りたいです。