簡體   English   中英

使用WMI讀取注冊表項

[英]Reading registry keys using 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";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM