在命令行参数中传递应用程序的路径
本文关键字:应用程序 路径 命令行 参数 | 更新日期: 2023-09-27 18:31:24
在我的应用程序中,我传递了一些命令行参数来计划任务。
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
?
我相信您需要在转义中传递引号,以便可以通过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
一个类似的问题和答案:为什么"schtasks"不运行我的工作?