Mck
Mck

Reputation: 149

task scheduler is displaying an error "The specified query is invalid"

I am running Windows 10.

I'm trying to run a backup job (C:\WINDOWS\system32\robocopy.exe) using Task Scheduler. But I was getting issues. To figure out what was going on, I turned on the history log. Unfortunately since doing that, every time I click the History tab I get the following error:


Dialog Title: "Query Error"

Dialog Message: "One or more logs in the query have errors."

The table in the dialog: "Microsoft-Windows-Task-Scheduler/Operational | The specified query is invalid"

"The events displayed are partial results."

Nothing appears in the History pane, so I cannot debug either problem. Does anyone know what is going on?


I am having the exact same error as in

https://www.experts-exchange.com/questions/27676176/Query-Error-In-Microsoft-Task-Scheduler.html

The answer is at

http://www.minasi.com/forum/topic.asp?TOPIC_ID=27906


The answer site (www.minasi.com) is apparently moved and did not retain the answer so cannot try the fix that solved his problem.

Upvotes: 10

Views: 6545

Answers (2)

eltoddo
eltoddo

Reputation: 1

Wouldn't have found my issue if I hadn't stumbled across this thread! Thanks @anilech!

My issue was related, my tasks themselves didn't have any offending apostrophes/single-quotes, but the folder for my custom tasks did!

Makes sense. All of my custom tasks were exhibiting this behavior when I'd view their history. Had no effect on the tasks actually logging properly, just Task Scheduler's ability to display history of the individual custom tasks.

Was a bit of a pain to fix since neither tasks, nor their folders can be renamed! You must export them and modify their contents to remove the apostrophe before re-importing.

To not tempt fate, I deleted the previous tasks and "offensively named" Task Scheduler folder, then created the new renamed Task Scheduler folder before re-importing; wasn't sure if Windows was smart enough to automatically create the Task Scheduler Library sub-folder for the updated URI.

Upvotes: 0

anilech
anilech

Reputation: 1119

Please check if you have single quotes (apostrophes) in the task name. It is known that the apostrophe in the task name breaks task history. To remove them you can try following batch file (it exports task to the xml file, imports it with the new name and removes the old task):

@set "tn=my PC's task"
@if not "%tn%"=="%tn:'=%" echo renaming "%tn%" ==^> "%tn:'=%" && ^
schtasks.exe /query /tn "%tn%" /xml>"%temp%\%tn:\=_%.xml" && ^
schtasks.exe /create /tn "%tn:'=%" /xml "%temp%\%tn:\=_%.xml" && ^
schtasks.exe /delete /tn "%tn%" /f && del /q /f "%temp%\%tn:\=_%.xml"

Upvotes: 13

Related Questions