简体   繁体   English

Python 脚本不会在任务计划程序中运行“无论用户是否登录都运行”

[英]Python script will not run in Task Scheduler for "Run whether use is logged on or not"

I have written a python script and wanted to have it run at a set period everyday with the use of Task Scheduler.我已经编写了一个 python 脚本,并希望使用任务计划程序让它每天在设定的时间段内运行。 I have had no problems with Task Scheduler for running programs while logged off, before creating this task.在创建此任务之前,我在注销时运行程序的任务计划程序没有任何问题。

If I select "Run only when user is logged on" my script runs as expected with the desired result and no error code (0x0).如果我选择“仅在用户登录时运行”,我的脚本将按预期运行,并获得所需的结果并且没有错误代码 (0x0)。

If I select "Run whether user is logged on or not" with "Run with highest privileges" and then leave it overnight or log off to test it, it does not do anything and has an error code of 0x1.如果我用“以最高权限运行”选择“无论用户是否登录都运行”,然后让它过夜或注销以测试它,它不会做任何事情并且错误代码为 0x1。

I have the action to "Start a program" with the Details as follows:我有“启动程序”的操作,详细信息如下:

Program/script : C:\Python27\python2.7.exe Add arguments : "C:\Users\me\Desktop\test.py"程序/脚本:C:\Python27\python2.7.exe添加参数:“C:\Users\me\Desktop\test.py”

I think it has to do with permissions to use python while logged off but I can't figure this one out.我认为这与注销时使用 python 的权限有关,但我无法弄清楚这一点。 Wondering if anyone has suggestions or experience on this.想知道是否有人对此有建议或经验。

This is on Windows 7 (fyi)这是在 Windows 7 上(仅供参考)

Thanks, JP谢谢,JP

I think I have found the solution to this problem.我想我已经找到了解决这个问题的方法。 My script is used to create a powerpoint slide deck and needs to open MS PPT.我的脚本是用来制作powerpoint幻灯片的,需要打开MS PPT。

I stumbled upon a post from another forum with a link to MS's policy on this.我偶然发现了另一个论坛的帖子,其中包含 MS 对此政策的链接。 It basically boils down to the following:它基本上归结为以下几点:

"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 behaviour and/or deadlock when Office is run in this environment. “微软目前不推荐也不支持任何无人值守、非交互式客户端应用程序或组件(包括 ASP、ASP.NET、DCOM 和 NT 服务)的 Microsoft Office 应用程序自动化,因为 Office 可能表现出不稳定的行为和/或在此环境中运行 Office 时出现死锁。

Automating PowerPoint from a scheduled task falls under the unsupported scenario when scheduled task is run with the option "Run whether user logged on or not".当使用“无论用户是否登录时运行”选项运行计划任务时,从计划任务自动化 PowerPoint 属于不受支持的方案。 But, using it with "Run only when the user is logged on" option falls under the supported category."但是,将它与“仅在用户登录时运行”选项一起使用属于受支持的类别。”

From here这里

我会尝试使用不在您的用户目录中的脚本

I have experience supporting PowerPoint automation under the Task Scheduler by way of a C++ app called p3icli (available on sourceforge).我有通过名为 p3icli 的 C++ 应用程序(可在 sourceforge 上获得)在任务计划程序下支持 PowerPoint 自动化的经验。 This is the approach I successfully used:这是我成功使用的方法:

1) Add a command-line (-T) switch that indicates p3icli will run under Task Scheduler. 1) 添加一个命令行 (-T) 开关,指示 p3icli 将在任务计划程序下运行。

2) The command-line switch forces p3icli to start an instance of powerpnt.exe using CreateProcess() and then wait X milliseconds for that instance to stabilize. 2) 命令行开关强制 p3icli 使用CreateProcess()启动 powerpnt.exe 的实例,然后等待 X 毫秒以使该实例稳定。

3) After X milliseconds elapse, p3icli connects to the running PPT instance created in step 2 and processes automation commands. 3) X 毫秒后,p3icli 连接到在步骤 2 中创建的正在运行的 PPT 实例并处理自动化命令。

I would guess that a similar approach can be used with Python.我猜想 Python 也可以使用类似的方法。

Task Scheduler compatibility is easily the most troublesome feature I ever added to p3icli.任务计划程序兼容性很容易成为我添加到 p3icli 的最麻烦的功能。 For example, manipulating multiple presentations by changing the active window simply does not work.例如,通过更改活动窗口来操作多个演示文稿根本不起作用。 And as I'm sure you've discovered, debugging problems is no fun at all.而且我相信您已经发现,调试问题一点也不好玩。

NB: Your python solution must include code that forces PowerPoint to unconditionally close when your python script is complete (modulo a python crash).注意:您的 python 解决方案必须包含强制 PowerPoint 在您的 python 脚本完成时无条件关闭的代码(以 python 崩溃为模)。 Otherwise, orphaned instances of PowerPoint will appear in Task Manager.否则,孤立的 PowerPoint 实例将出现在任务管理器中。

Click the link for some thoughts on the Task Scheduler from a p3icli point of view .单击链接以从 p3icli 的角度了解有关任务计划程序的一些想法。

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

相关问题 使用windows10任务调度程序运行python脚本,使用win32运行excel文件。 每当用户登录或未登录时 - Using windows10 task scheduler to run python script that uses win32 to run excel file. Whenever user is logged in or not win32com:任务计划程序:如何“无论用户是否登录都运行” - win32com: Task Scheduler: how to "run whether user is logged on or not" 批处理文件中的Python脚本无法在任务计划程序中运行 - Python script from batch file won't run in task scheduler 任务调度程序运行我的 python 脚本,但它什么也不做 - Task scheduler run my python script but it does nothing 无法安排 python 脚本通过 Windows 任务计划程序运行 - Cannot schedule a python script to run through Windows Task Scheduler 我的 Python 脚本无法从任务计划程序运行 - My Python Script does not run from Task Scheduler 通过任务计划程序运行时,Python脚本未创建文件 - Python Script not creating file when run through Task Scheduler 任务计划程序打开命令提示符但不运行 python 脚本 - Task Scheduler opens command prompt but does not run python script Windows 任务计划程序无法运行 Python 脚本,错误值:2147944320 - Windows Task Scheduler unable to run Python Script, error value: 2147944320 如何使用带参数的任务计划程序运行 python 脚本 - How to run a python script using Task Scheduler with parameters
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM