c# – 使用WMI读取注册表项
发布时间:2020-12-15 05:38:37 所属栏目:百科 来源:网络整理
导读:我试图通过使用WMI读取注册表项.我尝试使用以下代码,但我无法获取注册表项值. 任何人都可以帮我解决这个问题. ConnectionOptions oConn = new ConnectionOptions();System.Management.ManagementScope scope = new System.Management.ManagementScope(@""
我试图通过使用WMI读取注册表项.我尝试使用以下代码,但我无法获取注册表项值.
任何人都可以帮我解决这个问题. ConnectionOptions oConn = new ConnectionOptions(); System.Management.ManagementScope scope = new System.Management.ManagementScope(@"" +hostname + @"rootcimv2",oConn); scope.Connect(); ManagementClass registry = new ManagementClass(scope,new ManagementPath("StdRegProv"),null); ManagementBaSEObject inParams = registry.GetMethodParameters("GetStringValue"); inParams["sSubKeyName"] = "HKEY_LOCAL_MACHINESOFTWAREMicrosoft.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"] = "SOFTWAREMicrosoft.NETFramework"; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |