c# - 使用 WMI 读取注册表项

标签 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();

}

注意:我只想使用 WMI 读取注册表项。

最佳答案

您必须设置 hDefKey 的值(hive) 参数并从 sSubKeyName 参数中删除配置单元。

inParams["hDefKey"] =0x80000002;// HKEY_LOCAL_MACHINE;
inParams["sSubKeyName"] = "SOFTWARE\\Microsoft\\.NETFramework";

关于c# - 使用 WMI 读取注册表项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16919336/

相关文章:

c# - C# 中 Pipeline 和 PowerShell 类的区别

powershell - WMI 事件订阅和 PowerShell 执行

powershell - 如何从Get-WMIObject输出Powershell中删除多余的行

c# - 使用 WMI 远程卸载应用程序

c# - 计算9 :00 AM -- 6:00 PM之间的时间

c# - Entity Framework : Problem associating entities with nullable field

c# - Blazor MudSelect @bind-SelectedValues 到 id 和 value

Windows:更改与文件类型关联的应用程序的名称/图标

C++ - RegCreateKeyEx 成功但没有结果

python - Python从注册表中读取HKEY CURRENT USER,指定用户