1

In my application, I am passing some command line arguments to schedule a task.
str is a string which after some operations becomes

/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 ?

Cipher
  • 5,894
  • 22
  • 76
  • 112

1 Answers1

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?

Community
  • 1
  • 1
yamen
  • 15,390
  • 3
  • 42
  • 52