I am using the schtask
command with PowerShell. The problem that occurs is, when the program/script argument contains C:\Program Files\
, it thinks the path is just C:\Program
and the rest of the path is an argument. I have tried to escape it by using "
pre- and post- field, but it did n'tmake a difference. How can I accomplish this? I cannot hard-code the path because it can be changed when the user installs it.
I was creating this in Windows 7 x64. It creates the task OK and the script returns. However, when I view it in the Task Scheduler, properties of the task, then actions, and hit edit
, It shows the program as C:\Program and then the rest as the argument.
Script:
$folder = Split-Path $MyInvocation.MyCommand.Path -Parent
$app = "\Demon.DatabasePurge.exe"
$exe = $app.Insert(0, $folder)
schtasks /create /tn "Demon Purge Job" /sc daily /st 00:00:00 /tr $exe
Here is what I tried:
$folder = Split-Path $MyInvocation.MyCommand.Path -Parent
$app = "\Demon.DatabasePurge.exe`""
$exe = $app.Insert(0, $folder)
$exe2 = $exe.Insert(0, "`"")
schtasks /create /tn "Demon Purge Job" /sc daily /st 00:00:00 /tr $exe2