Adding a URL Exemption in c#
The system contains a list of applications which are exempted from parental controls. This list can be accessed via WMI and it should be modified in the install process for any application that requires free Internet access. The way to do this is to access the class via WMI and add the specified program into the list of app's. Here is an example written in C# to do just this.
There are two properties on the WMI object which have to do with the application exemption list. There is the HTTPExemptionList and the WinHTTPExemptionList, the HTTPExemption list is the one that is used to add in extra programs. The WinHTTPExemptionList is a readonly property that cannot be changed, it has some internal system exemptions.
using System;
using System.Collections.Generic;
using System.Text;
using System.Management;
namespace AddUrlExemption
{
public class SystemSettings
{
private ManagementObject _systemSettings;
public SystemSettings()
{
_systemSettings = new ManagementObject(
@"root\CIMV2\Applications\WindowsParentalControls",
"WpcSystemSettings=@",
new ObjectGetOptions());
}
public List<string> AppOverrides
{
get
{
string[] urls = (string[])_systemSettings["HTTPExemptionList"];
List<string> ret = new List<string>();
foreach (string url in urls)
{
ret.Add(url);
}
return ret;
}
set
{
string[] setting = new string[value.Count];
int pos = 0;
foreach (string url in value)
{
setting[pos] = url;
pos++;
}
_systemSettings["HTTPExemptionList"] = setting;
}
}
public ManagementPath Save()
{
return _systemSettings.Put();
}
}
class Program
{
static void PrintAppOverrides(List<string> list)
{
foreach (string s in list)
{
System.Console.WriteLine(" " + s);
}
}
static void Main(string[] args)
{
SystemSettings setting = new SystemSettings();
List<string> appOverrides = setting.AppOverrides;
System.Console.WriteLine("Start Overrides:");
PrintAppOverrides(appOverrides);
appOverrides.Add("c:\\windows\\bfsrv.exe");
setting.AppOverrides = appOverrides;
setting.Save();
System.Console.WriteLine("Added: c:\\windows\\bfsrv.exe");
}
}
}