【问题标题】:Passing path of an application in command line arguments在命令行参数中传递应用程序的路径
【发布时间】:2012-04-16 04:36:33
【问题描述】:

在我的应用程序中,我传递了一些命令行参数来安排任务。
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 ?

【问题讨论】:

    标签: c# command-line-arguments


    【解决方案1】:

    我相信您需要以转义的形式传递您的引号,以便schtasks 进程可以“提取”它们。您的字符串最终应该包含:

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

    但我怀疑它实际上包含:

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

    这意味着当你创建它时你应该定​​位:

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

    类似问答:Why "schtasks" does not run my job?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多