Change user parental control settings using WMI in C #

I am really new to WMI and COM.

I want to change some settings for user parental control accounts and the only API available is WMI. The WMI provider class to use is WpcUserSettings.

I do not understand how to change the settings for each user. Do I need to create a ManagmentObject of this class for each user or are they already created for each user.

If someone can give me sample code for a single user, it really will help.

Thanx!

EDIT: Hello again. I used your example to get user account names and SIDS. However, when I search for WpcUserSettings, there is no result, I used WMI Studio to check this class, and there is no instance, so I can not read or set the attributes. Do you have an idea how to fix this?

FIX: Ok, I found a trick. You must call the AddUser (SID) method for WpcSystemSettings using ManagementObject.InvokeMethod () for each user that you want to add to parental control. Then you can enable parental control in WpcUserSettings and do whatever you want.

+4
source share
1 answer

The WpcUserSettings class, which exists in the root\CIMV2\Applications\WindowsParentalControls namespace, does not provide any method for updating data by the user, but all displayed properties are read / write, with the exception of, obviously, the SID property. You can iterate over properties for a specific user and change values.

So you can make a Wmi request using a sentence similar to finding all users SELECT * FROM WpcUserSettings

or this sentence to change the properties of a specific user

SELECT * FROM WpcUserSettings Where SID="the SID of the user to modify"

then update the values โ€‹โ€‹of the properties you want to change, and finally call the Put method to set the new values.

check out this sample app.

 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(); } } } 
+3
source

Source: https://habr.com/ru/post/1346822/


All Articles