简体   繁体   English

命令行参数中应用程序的传递路径

[英]Passing path of an application in command line arguments

In my application, I am passing some command line arguments to schedule a task. 在我的应用程序中,我传递了一些命令行参数来安排任务。
str is a string which after some operations becomes str是一个字符串,经过一些操作后变成

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

And then I start a process as: 然后,我开始一个过程:

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

When I look into the task scheudler for the scheduled tasks, I get Action of schedules task as: 当我查看计划任务的任务调度程序时,将获得“计划任务的操作”为:

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

So, the problem is because of the space in Program Files. 因此,问题出在程序文件中。 How should I correct thing thing, so that the actual program remains 我应该如何纠正事物,以便保留实际程序
C:\\Program Files\\Internet Explorer\\iexplore.exe http://abc.com
and Arguments = http://abc.com ? Arguments = http://abc.com

I believe you need to pass your quotes in escaped so they can be 'extracted' by the schtasks process. 我相信您需要将引号引号转义,以便可以通过schtasks流程“提取”它们。 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? 一个类似的问题和答案: 为什么“ schtasks”不能执行我的工作?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM