C#控制台程序作为计划任务运行时无法发送传真

时间:2021-05-24 02:15:04

I have a console program written in C# that I am using to send faxes. When I step through the program in Visual Studio it works fine. When I double click on the program in Windows Explorer it works fine. When I setup a Windows scheduled task to run the program it fails with this in the event log.

我有一个用C#编写的控制台程序,用于发送传真。当我在Visual Studio中单步执行该程序时,它工作正常。当我在Windows资源管理器中双击该程序时,它工作正常。当我设置Windows计划任务来运行程序时,它会在事件日志中失败。

EventType clr20r3, P1 consolefaxtest.exe, P2 1.0.0.0, 
P3 48bb146b, P4 consolefaxtest, P5 1.0.0.0, P6 48bb146b, 
P7 1, P8 80, P9 system.io.filenotfoundexception, 
P10 NIL.

I wrote a batch file to run the fax program and it fails with this message.

我写了一个批处理文件来运行传真程序,它失败并显示此消息。

Unhandled Exception: System.IO.FileNotFoundException: Operation failed.
at FAXCOMEXLib.FaxDocumentClass.ConnectedSubmit(FaxServer pFaxServer)

Can anyone explain this behavior to me?

任何人都可以向我解释这种行为吗?

6 个解决方案

#1


5  

I can't explain it - but I have a few ideas.

我无法解释 - 但我有一些想法。

Most of the times, when a program works fine testing it, and doesn't when scheduling it - security is the case. In the context of which user is your program scheduled? Maybe that user isn't granted enough access.

大多数情况下,当一个程序对它进行精细测试时,并且在安排它时没有 - 安全性就是这种情况。在用户是您的计划安排的上下文中?也许该用户未获得足够的访问权限。

Is the resource your programm is trying to access a network drive, that the user running the scheduled task simply haven't got?

您的程序正在尝试访问网络驱动器的资源,运行计划任务的用户是否还没有?

#2


0  

Check that you set correct working directory for your task

检查是否为任务设置了正确的工作目录

#3


0  

Is the scheduled task running on the same computer you're developing on, or is it on a dedicated olp server? It's quite common for paths to change when you change environments, so is the path to the document you're trying to send the same?

计划任务是在您正在开发的同一台计算机上运行,​​还是在专用的olp服务器上运行?更改环境时路径更改是很常见的,您尝试发送的文档的路径也是如此?

#4


0  

I agree with MartinNH.

我同意MartinNH。

Many of these problems root from the fact that you develop while logged in as an administrator in Visual Studio (so the program has all the permissions for execution set properly) but you deploy as a user with lesser privileges.

其中许多问题源于您在Visual Studio中以管理员身份登录时开发(因此程序具有正确执行权限的所有权限),但您部署为具有较少权限的用户。

Try setting the priveleges of the task scheduler user higher.

尝试将任务调度程序用户的权限设置得更高。

#5


0  

If you are running in Vista, you may find that the elevation is getting in the way. You may need to ensure your task runs as a proper administrator, not as a restricted user.

如果您在Vista中运行,您可能会发现高程正在阻碍。您可能需要确保您的任务作为适当的管理员运行,而不是作为受限用户运行。

#6


0  

When you run a schedule task you can have it run under a user. Verify the user that is running the schedule task has the same rights for the fax resource as you. Which is why you can run it when you double click in Windows explore.

运行计划任务时,可以让它在用户下运行。验证正在运行计划任务的用户是否具有与您相同的传真资源权限。这就是为什么在Windows explore中双击时可以运行它的原因。

#1


5  

I can't explain it - but I have a few ideas.

我无法解释 - 但我有一些想法。

Most of the times, when a program works fine testing it, and doesn't when scheduling it - security is the case. In the context of which user is your program scheduled? Maybe that user isn't granted enough access.

大多数情况下,当一个程序对它进行精细测试时,并且在安排它时没有 - 安全性就是这种情况。在用户是您的计划安排的上下文中?也许该用户未获得足够的访问权限。

Is the resource your programm is trying to access a network drive, that the user running the scheduled task simply haven't got?

您的程序正在尝试访问网络驱动器的资源,运行计划任务的用户是否还没有?

#2


0  

Check that you set correct working directory for your task

检查是否为任务设置了正确的工作目录

#3


0  

Is the scheduled task running on the same computer you're developing on, or is it on a dedicated olp server? It's quite common for paths to change when you change environments, so is the path to the document you're trying to send the same?

计划任务是在您正在开发的同一台计算机上运行,​​还是在专用的olp服务器上运行?更改环境时路径更改是很常见的,您尝试发送的文档的路径也是如此?

#4


0  

I agree with MartinNH.

我同意MartinNH。

Many of these problems root from the fact that you develop while logged in as an administrator in Visual Studio (so the program has all the permissions for execution set properly) but you deploy as a user with lesser privileges.

其中许多问题源于您在Visual Studio中以管理员身份登录时开发(因此程序具有正确执行权限的所有权限),但您部署为具有较少权限的用户。

Try setting the priveleges of the task scheduler user higher.

尝试将任务调度程序用户的权限设置得更高。

#5


0  

If you are running in Vista, you may find that the elevation is getting in the way. You may need to ensure your task runs as a proper administrator, not as a restricted user.

如果您在Vista中运行,您可能会发现高程正在阻碍。您可能需要确保您的任务作为适当的管理员运行,而不是作为受限用户运行。

#6


0  

When you run a schedule task you can have it run under a user. Verify the user that is running the schedule task has the same rights for the fax resource as you. Which is why you can run it when you double click in Windows explore.

运行计划任务时,可以让它在用户下运行。验证正在运行计划任务的用户是否具有与您相同的传真资源权限。这就是为什么在Windows explore中双击时可以运行它的原因。