【问题标题】:Errors scheduling a C# console app that sends faxes via FAXCOMEXLib安排通过 FAXCOMEXLib 发送传真的 C# 控制台应用程序时出错
【发布时间】:2011-10-31 17:42:01
【问题描述】:

我有一个用 C# 编写的控制台应用程序,它使用 MS Fax (FAXCOMEXLib) 来发送传真。如果我手动或从命令提示符运行应用程序,它会按预期工作。如果我使用任务计划程序计划应用程序或尝试使用计时器从服务运行,则在调用 FaxDocument 对象上的 ConnectedSubmit2 时它会失败。应用程序按预期运行,获取数据,创建 pdf,连接到传真服务,填充 FaxDocument 属性,但在 ConnectedSubmit2 上发生了故障。感觉是安全问题。运行 TaskScheduler 的 windows 帐户属于管理员组。

同一应用程序已在另一台 Server 2008(不是 R2)计算机上运行,​​但任务计划程序没有问题。

有问题的服务器正在运行 Microsoft Server 2008 R2。

回顾:如果手动运行该应用程序将工作,如果从另一个进程(如任务计划程序)运行则失败。

任何建议将不胜感激。谢谢。

C#代码:

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;
}

事件日志中的错误:

  1. System.Runtime.InteropServices.COMException (0x80070102):操作失败。 在 FAXCOMEXLib.FaxDocumentClass.ConnectedSubmit2(IFaxServer pFaxServer, Object& pvFaxOutgoingJobIDs)
  2. System.UnauthorizedAccessException:访问被拒绝。在 FAXCOMEXLib.FaxDocumentClass.ConnectedSubmit2(IFaxServer pFaxServer, Object& pvFaxOutgoingJobIDs) 在 ElementsTransmission.Program.Main(String[] args)

【问题讨论】:

  • 您是否尝试过让计划任务在与手动运行此代码时使用的用户帐户相同的用户帐户下运行?如果可行,则可能是任务调度程序正在使用的帐户的权限存在问题。
  • 是的,我使用与当前登录 Windows 的管理员帐户相同的帐户来运行任务计划程序,但它不起作用。谢谢,
  • 我们也试过NetworkService账号,但没有成功。

标签: c# scheduled-tasks windows-server-2008-r2 fax


【解决方案1】:

【讨论】:

  • 请provide context获取您提供的链接。
  • 博文提供了上下文。
  • 来自我的链接:A link to a potential solution is always welcome, but please add context around the link so your fellow users will have some idea what it is and why it’s there . Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline. - 我们希望实际答案出现在您的帖子中,并提供链接作为对完整上下文的引用。就目前而言,这不是一个答案。
  • 出于礼貌而发布以帮助解决 OP 的问题。读者可以点击链接确定是否解决了问题。我没有遇到过这个问题,也没有测试过解决方案,所以我无法提供更多的上下文。
猜你喜欢
  • 1970-01-01
  • 2011-03-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多