我正在尝试禁用本地 Windows 帐户。在微软图书馆的帮助下,我能够写出这个ManagementScope mgmtScope = new ManagementScope("\\\\.\\Root\\CIMv2");ObjectQuery oQuery = new ObjectQuery("SELECT * FROM Win32_UserAccount");ManagementObjectSearcher mgmtSearch = new ManagementObjectSearcher(mgmtScope, oQuery);ManagementObjectCollection objCollection = mgmtSearch.Get();foreach (ManagementObject mgmtObject in objCollection){ if ((string)mgmtObject["Name"] == "test") { mgmtObject.SetPropertyValue("Disabled", true); Console.WriteLine("{0}", mgmtObject.GetPropertyValue("Disabled")); }}该GetPropertyValue函数告诉我该值已设置为“true”,但是当程序退出 foreach 循环时,该值再次设置为“false”。有谁知道为什么会这样?编辑:我终于找到了答案。我只需要使用该方法将更改应用于对象ManagementObject.Put()
添加回答
举报
0/150
提交
取消