When I type

c:\windows\system32\taskkill.exe /im somename.exe /t

in the run box of the scheduled tasks wizard,the job completes successfully,but if I used the windows command prompt instead and I typed the following:

schtasks /create /sc once /sd 01/01/2009 /st 16:16:16 /ru confused /rp bigheadache /tn sametask /tr c:\windows\system32\taskkill.exe /im somename.exe /t

I run into all sorts of syntax errors.It is very cofusing indeed! The path to the executable doesn't contain spaces.There is that mandatory space between the parameters and the executable,and I have tried quotes in all sorts of combinations but to no avail. Why is the CLI playing up?

The check box "only if I am logged on" is useless because even if it is not checked and you log out after setting the task the GUI s for the applications[that are in the schtasks list] would be invisible to you when you log in! Is there a work around for this annoyance?

Dani AI

Generated

was on the right track — the syntax errors come from how schtasks parses the /tr argument. /tr expects the entire command line as a single token, so if the command or its arguments contain spaces or look like switches, they must be kept together (quoting or using a wrapper avoids the scheduler interpreting parts as its own options).

A simple, robust approach is to put the real command in a small batch file and schedule that file. Example batch (save as C:\scripts\start_job.bat):

@echo off
"C:\Program Files\MyApp\myrunner.exe" -option "argument with spaces"

Then point schtasks at the .bat file (the path itself may still need quotes). This removes most quoting/escaping headaches and makes debugging easier.

About the GUI checkbox: “Run only when user is logged on” means the task runs interactively and any windows will be visible. “Run whether user is logged on or not” runs the task in a non-interactive/background session and any GUI will be hidden. On newer OSes session isolation prevents background tasks from showing UI at all. Workarounds: schedule an interactive logon/startup item (put a shortcut or script in the user’s Startup folder or use a logon script), use the schtasks interactive flag on supported systems, or (with caution) use PsExec’s interactive option to inject into the desktop. See the schtasks reference and PsExec page for details:

schtasks documentation
PsExec (Sysinternals)

Troubleshooting tips: test with a trivial script that writes to a file so you can confirm the task runs; log Task Scheduler history; avoid embedding special shell characters (&, |, >, %) in the /tr string — put them in the batch instead.

schtasks /create /sc once /sd 01/01/2009 /st 16:16:16 /ru confused /rp bigheadache /tn sametask /tr c:\windows\system32\taskkill.exe /im somename.exe /t should be typed as:

schtasks /create /sc once /sd 01/01/2009 /st 16:16:16 /ru confused /rp bigheadache /tn sametask /tr "c:\windows\system32\taskkill.exe /im somename.exe /t"

because whatever comes after /tr has to be a string and by using quotes we are telling the processor the whole expression is a string!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.