1
votes

I have a console app written in C# that uses MS Fax (FAXCOMEXLib) to send faxes. If I run the application manually or from a command prompt it works as expected. If I schedule the application with Task Scheduler or try to run from a service with a timer, it fails when calling the ConnectedSubmit2 on the FaxDocument object. The application runs as expected, gets the data, creates the pdf, connects to Fax Service, fills the FaxDocument properties, but bombs on ConnectedSubmit2. It feels like a security issue. The windows account the TaskScheduler runs under belongs to the administrator group.

This same application has worked on another Server 2008 (not R2) computer without issue with Task Scheduler.

The server in question is running Microsoft Server 2008 R2.

Recap: The application will work if run manually, fails if run from another process like Task Scheduler.

Any suggestions would be most appreciated. Thank you.

C# Code:

FAXCOMEXLib.FaxServer faxServer = new FAXCOMEXLib.FaxServer();
FAXCOMEXLib.FaxDocument faxDocument = new FAXCOMEXLib.FaxDocument();

ArrayList al = new ArrayList();
al.Add(orderPdfFilePath);
if (facesheetPdfFilePath != "")
    al.Add(facesheetPdfFilePath);

if (write) Console.WriteLine("Preparing to Connect to Fax Server...");
sbLog.Append("Preparing to Connect to Fax Server...\r\n");
faxServer.Connect("");
if (write) Console.WriteLine("Connected.");
sbLog.Append("Connected.\r\n");

// Add Sender Information to outgoing fax
faxDocument.Sender.Name = dr2["FacilityName"].ToString();
faxDocument.Sender.Department = dr2["TSID"].ToString();
faxDocument.Sender.TSID = Truncate(dr2["TSID"].ToString(), 20);
faxDocument.Recipients.Add(dr2["FaxNumber"].ToString(), dr2["Pharmacy"].ToString());
faxDocument.Bodies = al.ToArray(typeof(string));
faxDocument.Subject = order;

if (write) Console.WriteLine("Attempting submit to fax server...");
sbLog.Append("Attempting submit to fax server...\r\n");

// attempt send...
try
{
    object o;
    faxDocument.ConnectedSubmit2(faxServer, out o);    
    if (write) Console.WriteLine("Fax sent successfully " + DateTime.Now.ToString());
    sbLog.Append("Fax sent successfully " + DateTime.Now.ToString() + ".\r\n");

}
catch (Exception ex)
{
    if (write) Console.WriteLine("SEND FAILED! " + order + " " + DateTime.Now.ToString() + "  " + ex.Message);
    sbLog.Append("SEND FAILED! " + order + " " + DateTime.Now.ToString() + ".\r\n" + ex.Message + "\r\n" + ex.InnerException + "\r\n");
    error = true;
}

Errors in Event Log:

  1. System.Runtime.InteropServices.COMException (0x80070102): Operation failed. at FAXCOMEXLib.FaxDocumentClass.ConnectedSubmit2(IFaxServer pFaxServer, Object& pvFaxOutgoingJobIDs)
  2. System.UnauthorizedAccessException: Access denied. at FAXCOMEXLib.FaxDocumentClass.ConnectedSubmit2(IFaxServer pFaxServer, Object& pvFaxOutgoingJobIDs) at ElementsTransmission.Program.Main(String[] args)
1
Have you tried having the scheduled task run under the same user account as the one that you used for manually running this code? If that works, then it's likely an issue with permissions of the account that the task sceduler is using. - Brian Geihsler
Yes, I have used the same account to run Task Scheduler as the admin acccount currently logged into windows and it didn't work. Thanks, - nedhenry
We have also tried the NetworkService account with no luck. - nedhenry

1 Answers