简体   繁体   中英

Reading registry keys using WMI

I am trying to read the registry key by using WMI. I have tried with following code but i am unable to get the registry key value.

Can anyone help me regarding this problem.

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

}

Note: i want to read the registry keys by using WMI only.

You must set the value of the hDefKey (hive) parameter and remove the hive from the sSubKeyName parameter.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM