This project has moved. For the latest updates, please go here.

Error creating an event driven task

Topics: Errors
Aug 18, 2016 at 1:01 PM
I am trying to programmatically create a scheduled task that is based on a network connection event.

I am working from a XML export from a working task. Everything seems to be OK except I get variants on the following error when I call the RegisterTaskDefinitionMethod:

(11,365):Subscription:<QueryList><Query Id="0" Path="Microsoft - Windows - NetworkProfile / Operational"><Select Path="Microsoft - Windows - NetworkProfile / Operational">*[System[Provider[@Name='Microsoft-Windows-NetworkProfile'] and EventID=10000]]</Select></Query></QueryList>

Data = {System.Collections.ListDictionaryInternal}
HResult = -2147009896

I get variants on this error regardless of how I format the XML string. I can try the > and < format. I can try the actual symbols > <, etc. But basically the same error.

The query string is directly from a working task export to XML. If I change my program to update the XML I exported and go through the Microsoft.Win32.TaskScheduler namespace and simply import the updated XML, the task is created successfully.
Aug 19, 2016 at 4:55 PM
Here's a line from my test code that works:
eTrigger.Subscription = "<QueryList><Query Id=\"0\" Path=\"Security\"><Select Path=\"Security\">*[System[Provider[@Name='VSSAudit'] and EventID=25]]</Select></Query></QueryList>";
Hopefully that will help you see how to escape the string to get it entered properly.