WpcUserSettings
存在于命名空间中的wmi 类root\CIMV2\Applications\WindowsParentalControls
没有公开任何用户更新数据的方法,但所有公开的属性都是读/写的,除了明显的SID
属性。您可以迭代特定用户的属性并更改值。
因此,您可以使用类似语句的 Wmi 查询来检索所有用户
SELECT * FROM WpcUserSettings
或者这句话来修改特定用户的属性
SELECT * FROM WpcUserSettings Where SID="the SID of the user to modify"
然后更新您要修改的属性的值,最后调用该 Put
方法来设置新值。
检查此示例应用程序。
using System;
using System.Collections.Generic;
using System.Management;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2\\Applications\\WindowsParentalControls", "SELECT * FROM WpcUserSettings");
foreach (ManagementObject queryObj in searcher.Get())
{
if (queryObj["SID"] == "The user SID to modify")
{
//set the properties here
queryObj["AppRestrictions"] = true;
queryObj["HourlyRestrictions"] = true;
queryObj["LoggingRequired"] = false;
//queryObj["LogonHours"] = ;
//queryObj["OverrideRequests"] = ;
queryObj["WpcEnabled"] = true;
queryObj.Put();
}
}
}
catch (ManagementException e)
{
Console.WriteLine("An error occurred setting the WMI data: " + e.Message);
}
Console.ReadKey();
}
}
}