I am trying to use the Windows Process.start service in Visual Studios 2005 to call Windows task scheduler (schtasks) which calls the bat file. The process works fine except that the bat file takes in parameters but it won't work when I am trying to pass the parameters into the bat file.
public string RunSchtasks(string MachineName)
{
ErrorMessage = null;
Process myProcess = new Process();
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("schtasks");
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardError = true;
myProcessStartInfo.RedirectStandardOutput = true;
myProcessStartInfo.Arguments = "/run /s Machinename /tn mytest ParameterToPass2Bat";
myProcess.StartInfo = myProcessStartInfo;
try
{
myProcess.Start();
StreamReader myStreamReader1 = myProcess.StandardOutput;
string QueryResult = myProcess.StandardOutput.ReadToEnd();
}
My code runs fine without the ParameterToPass2Bat part. If I want to pass in this parameter into the bat file, it wouldn't take it. Does anyone know how to do it so that the bat file takes in the parameter through Schtasks?
Thanks!!!