I am trying to print pdf documents from a console program in C# that I need to automate. It works fine if I run it manually, but if I use the Windows 10 Task Scheduler, it does not work. I see Adobe Reader launched in Task Manager but it does not print out or attempt to print. No errors occur, it just opens adobe then closes it 10 seconds later as it supposed too. It is not the size of the files as it all works perfectly if executed directly on the desktop. It used to work fine, but appears to have stopped working since the Feature Update to Windows 10, version 1803 is installed, although it could also be a Adobe Reader update I guess. When it used to work the Adobe window used to come up on the screen and disappear (which was not a problem), and now since these updates everything is completely hidden, but it is launching! It's impossible to debug obviously as it's only in Task Scheduler, and it looks like it's working apart from the actual printing bit.
The c# code is pretty much the standard way of printing to Adobe:
public static Boolean PrintPDFs(string pdfFileName)
{
try
{
Process proc = new Process();
proc.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
proc.StartInfo.Verb = "print";
proc.StartInfo.FileName = System.Configuration.ConfigurationManager.AppSettings["Adobe_Path"];
proc.StartInfo.Arguments = String.Format(@"/o /p /h ""{0}""", pdfFileName);
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = false;
proc.EnableRaisingEvents = true;
proc.Start();
if (proc.HasExited == false)
{
proc.WaitForExit(10000);
}
proc.Close();
//Abobe sometimes hangs around so we kill it!
KillAdobe("AcroRd32");
return true;
}
catch (Exception ex)
{
Log.WriteLog(ex.Message);
return false;
}
}
Anyone have any ideas of how to get this working when scheduled under Task Scheduler? I am running Task Scheduler in an Administrator User Account with Highest privileges.
Thanks
Dave
I fixed it myself. For anyone who is interested basically in Task Scheduler I had it set to "Run whether the user is logged on or not" I changed this to "Run Only when the user is logged on" and it all started working again.