使用WMI读取注册表项

Sur*_*adi 5 c# registry wmi

我试图通过使用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();

}
Run Code Online (Sandbox Code Playgroud)

注意:我想仅使用WMI读取注册表项.

RRU*_*RUZ 4

您必须设置 (hive) 参数的值hDefKey并从该参数中删除 hive sSubKeyName

inParams["hDefKey"] =0x80000002;// HKEY_LOCAL_MACHINE;
inParams["sSubKeyName"] = "SOFTWARE\\Microsoft\\.NETFramework";
Run Code Online (Sandbox Code Playgroud)