Using the site: http://aymanstechblog.blogspot.com/2012/05/passing-event-details-as-arguments.html, I was able to set up an event-based task, and pass arguments from the event's description field (in event's XML: Event/EventData/Data) to the scheduled task's command, as arguments (in task's exported XML: Actions/Exec/Arguments).
使用该站点:http://aymanstechblog.blogspot.com/2012/05/passing-event-details-as-arguments.html,我能够设置基于事件的任务,并从事件的描述字段传递参数(在事件的XML:Event / EventData / Data中)到计划任务的命令,作为参数(在任务的导出XML中:Actions / Exec / Arguments)。
Using the above link's examples, I set up an "XML variable" in the EventTrigger/ValueQueries section (which I named "EventInfo"),
使用上面的链接示例,我在EventTrigger / ValueQueries部分(我命名为“EventInfo”)中设置了一个“XML变量”,
<Triggers>
<EventTrigger>
<Enabled>true</Enabled>
<Subscription><QueryList><Query Id="0" Path="Application"><Select Path="Application">*[System[Provider[@Name='triggerTestEvent']]]</Select></Query></QueryList></Subscription>
<ValueQueries>
<Value name="EventInfo">Event/EventData/Data</Value>
</ValueQueries>
</EventTrigger>
</Triggers>
and referenced it in the Actions/Exec/Arguments field of a scheduled task.
并在计划任务的Actions / Exec / Arguments字段中引用它。
<Actions Context="Author">
<Exec>
<Command>bin\triggerTestEvent.bat</Command>
<Arguments>$(EventInfo)</Arguments>
<WorkingDirectory>T:\Test</WorkingDirectory>
</Exec>
</Actions>
Using the command-line utility eventcreate
, I ran tests with sample data (none of which was a single character), and there was no issue; the scheduled task's command (a small batch file to simply write the args passed to a log file) showed everything was coming thru perfectly/as-expected.
使用命令行实用程序eventcreate,我使用示例数据(没有一个是单个字符)运行测试,并且没有问题;计划任务的命令(一个小的批处理文件,只是简单地写入传递给日志文件的args)显示一切都是通过完美/按预期进行的。
eventcreate /L application /so triggerTestEvent /id 101 /t INFORMATION /d "TEST #1"
However, I've encountered an issue when the data in the event is a single character.
但是,当事件中的数据是单个字符时,我遇到了一个问题。
eventcreate /L application /so triggerTestEvent /id 101 /t INFORMATION /d "1"
When this case is run, the variable replacement doesn't occur, and the "XML variable" string, $(EventInfo)
, is passed to the batch file, unchanged, and printed. I've tested with alphabetic vs. numeric vs. punctuation. Any single character causes the failure, but when the character is doubled, the value comes thru perfectly.
运行此情况时,不会发生变量替换,并且“XML变量”字符串$(EventInfo)将传递给批处理文件,不会更改并打印。我用字母与数字和标点符号进行了测试。任何单个字符都会导致失败,但是当字符加倍时,值就会完美无缺。
I've googled to no avail. I'm trying to find out if the issue is with me, or is it an actual bug in Scheduler's parsing of the event's XML.
我用谷歌搜索无济于事。我试图找出问题是否与我有关,或者它是Scheduler解析事件XML的实际错误。
1 个解决方案
#1
0
I did not tried your xml task, but a small error occurs in the use of tag "Command". You will have a better chance that it works in this way:
我没有尝试过你的xml任务,但是在使用标签“Command”时发生了一个小错误。你将有更好的机会以这种方式工作:
<Actions Context="Author">
<Exec>
<Command>%windir%\system32\cmd.exe</Command>
<Arguments>bin\triggerTestEvent.bat '$(EventInfo)'</Arguments>
<WorkingDirectory>T:\Test</WorkingDirectory>
</Exec>
</Actions>
(FYI, Microsoft is now going to strongly promote the use of powershell in tasks scripting)
(仅供参考,微软现在将强烈推动在任务脚本中使用powershell)
Best regards
#1
0
I did not tried your xml task, but a small error occurs in the use of tag "Command". You will have a better chance that it works in this way:
我没有尝试过你的xml任务,但是在使用标签“Command”时发生了一个小错误。你将有更好的机会以这种方式工作:
<Actions Context="Author">
<Exec>
<Command>%windir%\system32\cmd.exe</Command>
<Arguments>bin\triggerTestEvent.bat '$(EventInfo)'</Arguments>
<WorkingDirectory>T:\Test</WorkingDirectory>
</Exec>
</Actions>
(FYI, Microsoft is now going to strongly promote the use of powershell in tasks scripting)
(仅供参考,微软现在将强烈推动在任务脚本中使用powershell)
Best regards