I create a schedule tasks using the following command

SCHTASKS /Create /TN EventLog /SC ONEVENT /EC System /MO "*[System[Provider[@Name='WindowsUpdateClient'] and EventID=21]]" /TR "C:\Windows\System32\shutdown.exe -r -f -t 300"

After creating if I go to Task > Triggers > Edit Trigger It shows duplicate entry for the Source

Duplicate Entry for Source

Now if I manually delete this On an Event Trigger and then manually add the same trigger, then I do not see it as duplicate

No duplicate if manually added

What am I doing wrong in my SCHTASKS which is creating this duplicate entry and how to avoid it?


There's nothing wrong, it's actually a "feature". ;)

It's because you're allowed to reference any "Source" you want, whether it exists in the drop-down list or not.

Entries in drop-down lists are made of two elements, the Value and the Text. The "Text" is the text name shown to you, the Value is a number assigned to that entry. This allows you to have multiple entries with the same text (but you can't have more than one with the same Value).

So you create a new task with SchTasks, and provide a Source via XPath code in the Modifier option. You then go load the GUI. The GUI builds its drop-down entries by checking the system for known Event Sources, and then assigns each one a value and uses it's name as the displayed text. It then scans the task itself to add any custom ones, which will be assigned the next value available, and added to the list. The list is then alphabetized by the Text.

Short version: With SchTasks you are always defining a custom Source (from the GUIs point of view), so the GUI treats it as such and shows it to you, even if the text name is a duplicate of a known Event Source.

  • if i create tasks using SCHTASKS when i have duplicates then my task doesn't trigger but when i manually create the onEvent task then the task triggers. I would have to run more tests to confirm this – SeanClt May 4 '16 at 22:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.