简体   繁体   English

在“运行是否登录用户”模式下,使用任务计划程序运行Powershell脚本会冻结

[英]Running Powershell script using Task Scheduler freezes when in “Run whether user is logged in or not” mode

I currently have a Powershell script that can access Microsoft Outlook, and which I want to be executed automatically every x minutes. 我目前有一个可以访问Microsoft Outlook的Powershell脚本,我希望每x分钟自动执行一次。 For the latter part I created a task in Task Manager that fires the following command: 对于后一部分,我在任务管理器中创建了一个任务,该任务触发以下命令:

Powershell.exe -windowstyle minimized -c "powershell -c [PATH_TO_SCRIPT] -verbose >> [PATH_TO_LOG]"

This works perfectly fine, except for the problem that, even with the -windowstyle minimized flag, it still briefly opens a powershell window, that disappears to the background after 2 seconds or so. 这很好用,除了以下问题外,即使使用-windowstyle minimized标志,它仍然会短暂打开一个powershell窗口,该窗口在2秒钟左右后消失到后台。 A solution to this problem is to change the setting in Task Scheduler, checking "Run whether user is logged in or not". 解决此问题的方法是更改​​“任务计划程序”中的设置,并选中“运行用户是否已登录”。 However, at that point, my script doesn't execute anymore. 但是,到那时,我的脚本不再执行了。 From the logs I found that the script runs perfectly fine until the following line: 从日志中,我发现脚本运行良好,直到以下行:

$outlook = New-Object -ComObject Outlook.Application , $outlook = New-Object -ComObject Outlook.Application

the line on which I open the Outlook application. 打开Outlook应用程序的行。 I'm not sure what the "run whether user is logged in or not" option actually does, but whatever it is, it can no longer access an instance of my Outlook application. 我不确定“无论用户是否登录都可以运行”选项的实际作用,但是无论如何,它都无法再访问我的Outlook应用程序的实例。

Given what I actually want to achieve, could I tweak either my script or my task to fix this, or is there maybe another way to tackle this? 鉴于我实际想要实现的目标,我可以调整脚本或任务来解决此问题,还是有其他方法可以解决此问题?

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment. Microsoft当前不建议也不支持任何无人参与的非交互客户端应用程序或组件(包括ASP,ASP.NET,DCOM和NT Services)中的Microsoft Office应用程序自动化,因为Office可能表现出不稳定的行为和/在此环境中运行Office时出现死锁或死锁。

If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. 如果要构建在服务器端上下文中运行的解决方案,则应尝试使用对无人值守执行安全的组件。 Or, you should try to find alternatives that allow at least part of the code to run client-side. 或者,您应该尝试找到允许至少部分代码在客户端运行的替代方法。 If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. 如果您从服务器端解决方案中使用Office应用程序,则该应用程序将缺少许多成功运行所需的功能。 Additionally, you will be taking risks with the stability of your overall solution. 此外,您将承担整体解决方案稳定性的风险。 Read more about that in the Considerations for server-side Automation of Office article. 在《 服务器端Office自动化注意事项》一文中了解有关此内容的更多信息。

As a workaround you may consider using a low-level API instead - Extended MAPI. 解决方法是,您可以考虑使用低级API-扩展MAPI。 Or just any other third-party wrapper around that API such as Redemption. 或围绕该API的任何其他第三方包装,例如“兑换”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何Powershell任务管理器的脚本“无论用户是否登录都运行” - How to Powershell a script for Task Manager to "run whether a user is logged on or not" 使用PowerShell使用“运行是否用户已登录”选项来安排任务创建 - Schedule task creation with option “”Run whether user is logged in or not“” using powershell 如何在静默/隐藏模式下使用任务调度程序运行powershell脚本? - How to run powershell script using task scheduler in silent/hidden mode? 任务调度程序“无论用户是否登录都运行”问题到启动应用程序 - Task scheduler "Run whether user is logged on or not" issue to startup application 在任务计划程序中设置时,PowerShell脚本未运行 - PowerShell Script not running when set in the task scheduler 当用户未登录时,修改 Word 文件的 PowerShell 脚本不适用于任务计划程序 - PowerShell script that modifies Word file doesn't work with Task Scheduler when user isn't logged on 设置“无论用户是否登录都运行”时,PowerShell 不会作为计划任务运行 - PowerShell doesn't run as scheduled task when “Run whether user is logged on or not” is set 在任务计划程序上运行PowerShell脚本 - Running PowerShell Script on Task Scheduler Powershell 脚本未在任务计划程序上运行 - Powershell script not running on Task Scheduler 在Windows Task Scheduler中以其他用户身份运行的PowerShell脚本 - PowerShell script running as different user in Windows Task Scheduler
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM