【发布时间】:2016-02-03 20:46:59
【问题描述】:
我正在尝试按照 MSDN 中的一个示例使用 C# 更新 WMI 实例,但我无法让它工作。它给我一个“System.Management.ManagementException”,它没有给我任何答案。如果我做错了什么,你能告诉我吗?
public void UpdateInstance(string parametersJSON)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
object result = serializer.Deserialize(parametersJSON, typeof(object));
Dictionary<string, object> dic = (Dictionary<string, object>)result;
PutOptions options = new PutOptions();
options.Type = PutType.UpdateOnly;
ManagementObject objHostSetting = new ManagementObject();
objHostSetting.Scope = new ManagementScope("root\\onguard");
objHostSetting.Path = new ManagementPath("Lnl_Cardholder.SSNO = '33263085'"); // This is the line that fires the exception
foreach (KeyValuePair<string, object> value in dic)
{
objHostSetting[value.Key] = value.Value.ToString();
}
//update the ManagementObject
objHostSetting.Put(options);
}
【问题讨论】: