1

在我的应用程序中,我传递了一些命令行参数来安排任务。
str 是一个字符串,经过一些操作后变为

/create /tn StartIE /tr "C:\Program Files\Internet Explorer\iexplore.exe http://abc.com" /sc onlogon

然后我开始一个过程:

ProcessStartInfo ps = ProcessStartInfo("schtasks");
ps.Arguments = str;
Process.Start(ps);

当我查看计划任务的任务调度程序时,我得到计划任务的操作为:

C:\Program
and the Arguments as: Files\Internet Explorer\iexplore.exe http://abc.com

所以,问题是因为程序文件中的空间。我应该如何纠正事情,以便实际程序保持
C:\Program Files\Internet Explorer\iexplore.exe http://abc.com
不变Arguments = http://abc.com

4

1 回答 1

0

I believe you need to pass your quotes in escaped so they can be 'extracted' by the schtasks process. Your string should end up containing:

/create /tn StartIE /tr "C:\Program Files\Internet Explorer\iexplore.exe http://abc.com" /sc onlogon

But I suspect it actually contains:

/create /tn StartIE /tr C:\Program Files\Internet Explorer\iexplore.exe http://abc.com /sc onlogon

Which means when you create it you should be targetting:

/create /tn StartIE /tr \""C:\Program Files\Internet Explorer\iexplore.exe http://abc.com\"" /sc onlogon

A similar question and answer: Why "schtasks" does not run my job?

于 2012-04-16T04:50:17.167 回答