Using Custom Events in Windows Parental Controls

Any extension you add to Parental can log custom events, well any application can log custom events.  These events will show up in the activity viewer in the control panel.  To log a custom event you must first register the custom event using WMI and then log to the parental controls channel using crimson.

Note that once you have registered your custom event, nothing will show up in the activity viewer until you have logged a crimson event to channel.  I will show some c++ code for logging a custom event to the crimson channel in my next blog article.

Here is a small piece of jscript that will show all the currently registered custom events in the parental controls system.

// Setup some defines for the rest of the script, points to the local machine
// and the parental controls namespace.
strComputer = ".";
strRootNamespace = "\\ROOT\\CIMV2";
strNamespace = strRootNamespace + "\\Applications\\WindowsParentalControls";

// Connect to WMI.
strConnectStr = "winmgmts:\\\\" + strComputer + strNamespace;
wmi_service = GetObject(strConnectStr);

// Get all the instances of the WpcCustomEvent.
instances = wmi_service.InstancesOf("WpcCustomEvent");

// Loop through all the customevents and show them to the user.
str = "";
WScript.Echo("Count: " + instances.Count);
enumerator = new Enumerator(instances);
for (; !enumerator.atEnd(); enumerator.moveNext())
{
   ob = enumerator.item();
   str = str + "Publisher=" + ob.Publisher +
"; Application=" + ob.Application + "; Event=" + ob.Event + "; Headers=" + "\n";
}

WScript.Echo(str);

Here is a small piece of jscript that will register the specified custom event into the system.  This can be done in C++ or .net using very similar calls, just using jscript since it is one of the easiest ways to connect to WMI and do useful things.

// Setup some defines for the rest of the script, points to the local machine
// and the parental controls namespace.
strComputer = ".";
strRootNamespace = "\\ROOT\\CIMV2";
strNamespace = strRootNamespace + "\\Applications\\WindowsParentalControls";

// Connect to WMI.
strConnectStr = "winmgmts:\\\\" + strComputer + strNamespace;
wmi_service = GetObject(strConnectStr);

// Get a WpcCustomEvent object.
customOb = wmi_service.Get("WpcCustomEvent");

// Spawn a new instance of the event
ob = customOb.SpawnInstance_();

// Setup the instance.
ob.Publisher = "Froggy";
ob.Application = "Frog World";
ob.Event = "Frog Colour";
headers = new Array();
headers [0] = "Frog Name";
headers [1] = "Frog Location";
headers [2] = "Frog Colour";
ob.Headers = headers;

// Save the instance into WMI
strPath = ob.Put_(0);

// Show the path to the new instance.
WScript.Echo("Path: " + strPath);