Hi All,
I am pretty much in a dilemma situation now.
I had created a console application with c#, it is using a Process object to start another third party program.
When I run the console application that I created in command prompt, it works perfectly, but when I setup a scheduled task on Windows Server Box, the console application that executed by Windows Scheduled Task is not able to execute the third party application that is supposed to be triggered by Process object.
It works fine up to here when executed by Windows Scheduled Task (Rename a file):
string renamedFile = Misc.SetupProperDateTime(false) + _NewFileExtension; DateTime yesterday = DateTime.Now.Date.AddDays(-1); int temp = yesterday.Day; string fileName = _OriFilePrefix + temp.ToString() + _OriFileExtension; string[] files = Directory.GetFiles(originalFileLocation, "*" + _OriFileExtension, SearchOption.TopDirectoryOnly); // Move and re-name a File File.Move(files[0], Path.GetDirectoryName(files[0]) + @"\" + renamedFile); string newFile = originalFileLocation + renamedFile;
However, below codes doesnt create the output file while the console application wsa triggered by Scheduled Task:
Is there any flags i need to set on Process object before the object been started.string outputFile = string.Empty; try { if (isEncrypt == false) { using (Process process = new Process()) { string command = "a program"; string argument = @" -z " + code + " " + inputFile + " -o " + Path.GetDirectoryName(inputFile) + @"\" + Misc.SetupProperDateTime(false) + _TextFileExtension; ProcessStartInfo psi = new ProcessStartInfo(command, argument); process.StartInfo = psi; process.StartInfo.RedirectStandardOutput = false; process.StartInfo.UseShellExecute = true; process.Start(); process.WaitForExit(); outputFile = Path.GetDirectoryName(inputFile) + @"\" + Misc.SetupProperDateTime(false) + _TextFileExtension; }
} } catch (Exception ex) { WriteToLogFile(ex.Message); outputFile = ex.Message; } return outputFile;