Schtasks.exe with quotes

2

I use this command to create a task: schtasks /Create /TN ITCMD-CHAT-NOTIF /SC ONLOGON /tr "%cd%\Notif\Notif.vbs" /F

However a problem occurs. When there is a space in the path it still does not put quotes around the action. Is there a way to put quotes around the action?

Mark Deven

Posted 2018-10-02T14:31:52.647

Reputation: 1 101

Answers

3

This can be accomplished by nesting the two different quote characters. ("' followed by '" or "\" followed by \"")

schtasks /Create /TN ITCMD-CHAT-NOTIF /SC ONLOGON /tr "'%cd%\Notif\Notif.vbs'" /F

From the schtasks documentation:

==> Spaces in file paths can be used by using two sets of quotes, one
    set for CMD.EXE and one for SchTasks.exe.  The outer quotes for CMD
    need to be double quotes; the inner quotes can be single quotes or
    escaped double quotes:
    SCHTASKS /Create
       /tr "'c:\program files\internet explorer\iexplorer.exe'
       \"c:\log data\today.xml\"" ...

Worthwelle

Posted 2018-10-02T14:31:52.647

Reputation: 3 556

Good job, I was getting ready to look at this in more detail too!! – Pimp Juice IT – 2018-10-02T21:10:02.030