使用 Windows 任务计划程序运行批处理文件
我有一个批处理文件 daily.bat,这是代码:
cd C:\inetpub\wwwroot\infoweb\factuur\cron
c:\PHP\php.exe -f ./cron_pdf.php
ftp -s:ftp_upload.txt ftp.site.be
我在 Windows 7 中使用任务计划程序创建了一个任务。当我手动运行批处理时,一切正常,但是当我尝试使用任务计划程序运行它时,没有任何反应。
我的操作是
'run script' "C:\inetpub\wwwroot\site\x\cron\daily.bat"
UAC 已关闭,我是管理员。
知道为什么这不起作用吗?
I have a batch file daily.bat, this is the code:
cd C:\inetpub\wwwroot\infoweb\factuur\cron
c:\PHP\php.exe -f ./cron_pdf.php
ftp -s:ftp_upload.txt ftp.site.be
And I created a task with task scheduler in Windows 7. When I run the batch manually, everything goes fine, but when I try to run it with the task scheduler nothing happens.
My action is
'run script' "C:\inetpub\wwwroot\site\x\cron\daily.bat"
UAC is off and I am Admin.
Any idea why this is not working?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(18)
我在此处发布了此问题的答案 和此处。
I post the answer to this question here and here.
使用任务计划程序主窗口中的“运行”按钮测试了几种变体,最终找到了正确的设置。这两个选项必须结合起来:
- 仅当用户登录时运行
- 以最高权限运行。
所有其他变体都失败了。在这上面浪费时间真是令人气愤,但至少它有效。
操作系统:WINDOWS 8 核心(基本)版本
Using the Run button in the Task Scheduler main window to test several variations finally found the correct settings. This two options must be combined:
-Run only when user is logged on
-Run with highest privileges.
All other variations failed. It's infuriating all the time wasted on this, but at least it works.
OS: WINDOWS 8 CORE (BASIC) VERSION
请检查您使用哪个用户帐户来执行我们的任务。您可能会使用与默认用户不同的用户运行任务,并且该用户需要一些额外的权限。
此外,也可能会发生任务已执行但您看不到任何效果,因为批处理文件等待某些用户响应,因此如果您看到进程正在运行,请检查任务管理器。
一旦我用 svn 更新某个网页的批处理,进程就会挂起,因为 svn 要求接受服务器证书。
Please check which user account you use to execute our task. It may happen that you run your task with different user then your default user, and this user requires some extra privileges.
Also it may happen that the task is executed but you cant see any effect because the batch file waits for some user response so please check task manager if you see your process running.
Once it happen that I schedule a batch with svn update of some web page and the process hangs because svn asked for accepting server certificate.
C:\Necessary_file\Reqular_task\QDE\cmd_practice\
C:\Necessary_file\Reqular_task\QDE\cmd_practice\
尝试以高权限运行该任务。
在“开始于文件夹”中的路径末尾放置一个 \,例如 c:\temp\
我不知道为什么,但这有时对我有用。
Try run the task with high privileges.
put a \ at the end of path in "start in folder" such as c:\temp\
I do not know why , but this works for me sometimes.
操作:
启动程序
程序/脚本:
C:\Windows\System32\cmd.exe
添加参数:
/k start "" "E:\scripts\ example.bat"
将
exit
添加到批处理文件的末尾。如果您选择
无论用户是否登录都运行
,将不会显示 cmd 窗口。您需要选择仅在用户登录时运行
才能查看正在运行的窗口。Action:
Start a Program
Program/script:
C:\Windows\System32\cmd.exe
Add arguments:
/k start "" "E:\scripts\example.bat"
Add
exit
to the end of your batch file.The cmd window will not show if you select
Run whether user is logged in or not
. You need to selectRun only when user is logged on
to see the window in action.就我而言,Windows 仅当我解决了两个“问题”时才同意执行脚本:
“C:\My_script_directory\My_script.bat”-> “C:/My_script_directory/My_script.bat”
“添加参数”和“开始于”字段留空。
万岁!它还活着!
In my case Windows has agreed to execute script only when I have resolved two "problems":
"C:\My_script_directory\My_script.bat" -> "C:/My_script_directory/My_script.bat"
"Add arguments" and "Start in" fields were left empty.
And Hurray! It's alive!
我遇到了同样的问题,但我找到了另一个解决方案,而无需修改我的批处理脚本。
我唯一错过的是“操作”设置 - “开始于(可选)”选项。
转到任务属性-->操作选项卡 -->编辑-->填写如下:
C:\Users\beruk\bodo.bat
C:\Users\beruk\
(不要在“开始于”两边加上引号)然后单击“确定
”对我有用。祝你好运!
I faced the same problem, but I found another solution without having to modify my batch script.
The only thing that I missed out is at the 'Action' settings - "Start in (Optional)" option.
Go the task properties --> Action tab --> Edit --> Fill up as below:
C:\Users\beruk\bodo.bat
C:\Users\beruk\
(Do not put quotes around Start In)Then Click OK
It works for me. Good Luck!
上述方法均无效。我按照教程中所说的方式尝试过,并且有效。
操作:
程序/脚本:
添加参数:
在 Win7 Pro 上为我工作。您必须有一个有密码的帐户(空白密码不好)
None of the above method worked. I tried it this way as said it in a tutorial and it worked.
Action:
Program/script:
Add arguments:
Worked for me on Win7 Pro. You must have an account with a password (blank passwords are no good)
对于那些 bat 文件在 Windows 8 和 10+ 任务计划程序中仍然无法工作的人,我想在 Ghazi 的答案中添加一件事 - 在经历了很多痛苦之后:
这对我来说是这样,加上其他不要忘记的问题:
这无需触发命令提示符即可工作。而且这是最快、最简单的方法。
(抱歉,我的代表太低,无法将我的基本任务提示添加到 Ghazi 的评论中)
For those whose bat files are still not working in Windows 8 and 10+ Task Scheduler , one thing I would like to add to Ghazi's answer - after much suffering:
That did it for me, plus the other issues not to forget:
This worked without any need to trigger a command prompt. And it is the quickest and simplest method.
(Sorry my rep is too low to add my Basic Task tip to Ghazi's comments)
确保“开始于”没有引号。
Make sure "Start In " has NO QUOTES.
我的脚本是从 master 中提取最新代码并发布一个新分支
My script was to pull latest code from master and publish a new branch
现在正在工作。这就是我所做的。您可能不需要所有这些步骤来使其工作,但只是为了确保尝试所有这些步骤:
检查计划任务的帐户参数并确保它们设置为运行,无论是否有人登录到计算机
检查以大多数特权/权限运行
确保首先转到完整路径:cd C:\inetpub\wwwroot\infoweb\factuur\cron
不要在批处理文件中使用双引号(不知道为什么,但似乎有帮助)
成为超级管理员,在命令提示符中输入“网络用户管理员 /active:yes”,注销并以超级管理员身份登录,因此 UAC 关闭
It is working now. This is what I did. You probably won't need all these steps to make it work but just to be sure try them all:
Check the account parameters of your scheduled task and make sure they are set to run whether or not someone is logged into the machine
check run with most privileges/rights
Make sure you go to the full path first: cd C:\inetpub\wwwroot\infoweb\factuur\cron
Don't use double quotes in your batch files (don't know why but seems to help)
Be super admin, enter 'Net user administrator /active:yes' in command prompt, log out and log in as the super admin, so UAC is off
确保“开始于”不以反斜杠结尾。
Make sure "Start In" does NOT end with a BACKSLASH.
有一个问题,我的任务没有触发,只是因为它在没有电源线的笔记本电脑上运行...在“条件”选项卡下,默认情况下会选中它,以便在未连接交流电源时任务不会运行。
Had an issue where my task was not firing simply because it was running on a laptop without a power cord... Under the conditions tab, by default it is checked so that a task will not run while AC power is not connected.
在Windows7 Pro下,我发现Arun的解决方案对我有用:即使在“没有用户登录”的情况下我也可以让它工作,我确实选择了使用最高权限。
根据过去的经验,您必须拥有一个带有密码的帐户(空白密码不好),如果程序在完成向导时没有提示您输入密码,请返回并编辑一些内容,直到出现为止!
这是一种方法,以防不清楚哪种方法有效
Under Windows7 Pro, I found that Arun's solution worked for me: I could get this to work even with "no user logged on", I did choose use highest priveledges.
From past experience, you must have an account with a password (blank passwords are no good), and if the program doesn't prompt you for the password when you finish the wizard, go back in and edit something till it does!
This is the method in case its not clear which worked
我搞砸了几个小时并尝试了许多不同的建议。
我终于通过执行以下操作使其工作:
I messed with this for several hours and tried many different suggestions.
I finally got it to work by doing the following:
如果此处所有其余操作均失败,请确保您尝试运行任务的用户有权访问您尝试使用的文件。
就我而言,我尝试从 C:\Users\Administrator\Desktop 运行该帐户无法访问的批处理文件。将其移动到 C:\ 上的中立位置解决了该问题。
If all of the rest fails for you here ensure that the user you are trying to run the task as has access to the file you're trying to use.
In my case I was trying to run a batch file from C:\Users\Administrator\Desktop which the account couldn't access. Moving it to a neutral location on C:\ resolved the issue.