The Query Id attribute must be numeric. I got the following to work:

for (10000..10001) { die Win32::OLE->LastError() unless (push @Triggers, $TriggerSet->C +reate(0)); $Triggers[$#Triggers]->{Id} = $_; $Triggers[$#Triggers]->{Subscription} = qq{<QueryList> <Query Id="$_" Path="Microsoft-Windows-NetworkProfile/Operat +ional"> <Select Path="Microsoft-Windows-NetworkProfile/Operational +">*[System[(EventID="$_")]]</Select> </Query> </QueryList>}; die Win32::OLE->LastError() unless (my $values = $Triggers[$#Triggers]->ValueQueries->Create("ev +entId", "Event/System/EventID")); $Triggers[$#Triggers]->{Enabled} = 1; }

The relevant, magic change is matching

$Triggers[$#Triggers]->{Id} = $_;
and
<Query Id="$_" Path="Microsoft-Windows-NetworkProfile/Operational" +>
Maybe you can change both to be non-numeric, but with that change, I created tasks that I was able to view them afterwards.

Some stylistic notes:

Don't use double-quoted strings with (many) escaped backslashes in them. Instead, use one of the alternate quoting mechanisms, like qq{...} to prevent excessive backslashitis.

For easier testing, do both calls at the end of your program:

warn "Testing query"; $RootFolder->RegisterTaskDefinition("OLE-Test",$TaskDefinition,1,undef +,undef,3); warn "Query OK, installing task"; $RootFolder->RegisterTaskDefinition("OLE-Test",$TaskDefinition,6,undef +,undef,3); print Dumper $TaskDefinition->{XmlText};

In reply to Re: Win32::OLE and Task Scheduling - Invalid Query by Corion
in thread Win32::OLE and Task Scheduling - Invalid Query by kambe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.