带有空格的任务的 Powershell 和 schtask [英] Powershell and schtask with task that has a space

查看:33
本文介绍了带有空格的任务的 Powershell 和 schtask的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 PowerShell 中使用 schtask 命令.出现的问题是,当 program/script 参数包含 C:\Program Files\ 时,它认为路径只是 C:\Program 和路径的其余部分是一个论点.我试图通过使用 " 前字段和后字段来逃避它,但它并没有什么区别.我怎样才能做到这一点?我无法对路径进行硬编码,因为它可以在用户安装时更改.

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.

我是在 Windows 7 x64 中创建的.它创建任务 OK 并且脚本返回.但是,当我在任务计划程序中查看它时,任务的属性,然后是操作,然后点击 edit,它显示程序为 C:\Program,然后其余的作为参数.

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.

脚本:

$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

这是我尝试过的:

$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

推荐答案

我也遇到了这个问题.. 其他有这个问题的人的答案是包含单引号

I was having problems with this as well.. anyone else with this issue the answer is to include single quotes

/TR "'C:\Program Files (x86)\etc\test.exe'"

这篇关于带有空格的任务的 Powershell 和 schtask的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆