using System.Diagnostics.Process and schtasks to create a task.

D

David Gerler

I have a method that I wrote to create a task using
System.Diagnostics.Process and schtasks.

I am able to create the task and it runs fine until I add an arguement for
the task command. i.e. C:\program files\autoupdate.exe CHECK

Here is my method:
private static void scheduleAutoUpdate(string mode, string time)
{
Process schedule = new Process();
schedule.StartInfo.FileName = "schtasks";
schedule.StartInfo.Arguments = "/create /tn \"AutoUpdate " +
mode + "\" /ru System"
+ " /tr \"\"\"\"C:\\program
files\\GIS\\autoupdate\\autoupdate.exe\"\"\"\" /sc daily /st " + time + ":00";
schedule.Start();
}

As you see, I have included four sets of escaped dbl quotes to handle the
space in the path. However if I add "CHECK" as an agrument, it doesn't create
the task. I have tried:
\"\"\"\"C:\\program files\\GIS\\autoupdate\\autoupdate.exe\"\"\"\" CHECK
\"\"\"\"C:\\program files\\GIS\\autoupdate\\autoupdate.exe\"\" CHECK\"\"
\"\"\"\"\"\"C:\\program files\\GIS\\autoupdate\\autoupdate.exe\"\"\"\"
CHECK\"\"

Can anyone tell me what I need to do?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top