【发布时间】: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;
}
事件日志中的错误:
- System.Runtime.InteropServices.COMException (0x80070102):操作失败。 在 FAXCOMEXLib.FaxDocumentClass.ConnectedSubmit2(IFaxServer pFaxServer, Object& pvFaxOutgoingJobIDs)
- System.UnauthorizedAccessException:访问被拒绝。在 FAXCOMEXLib.FaxDocumentClass.ConnectedSubmit2(IFaxServer pFaxServer, Object& pvFaxOutgoingJobIDs) 在 ElementsTransmission.Program.Main(String[] args)
【问题讨论】:
-
您是否尝试过让计划任务在与手动运行此代码时使用的用户帐户相同的用户帐户下运行?如果可行,则可能是任务调度程序正在使用的帐户的权限存在问题。
-
是的,我使用与当前登录 Windows 的管理员帐户相同的帐户来运行任务计划程序,但它不起作用。谢谢,
-
我们也试过NetworkService账号,但没有成功。
标签: c# scheduled-tasks windows-server-2008-r2 fax