使用 Windows 任务计划程序运行批处理文件

发布于 2024-10-08 00:03:47 字数 389 浏览 0 评论 0原文

我有一个批处理文件 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(18

神妖 2024-10-15 00:03:48

I post the answer to this question here and here.

enter image description here

桃酥萝莉 2024-10-15 00:03:48

使用任务计划程序主窗口中的“运行”按钮测试了几种变体,最终找到了正确的设置。这两个选项必须结合起来:
- 仅当用户登录时运行
- 以最高权限运行。
所有其他变体都失败了。在这上面浪费时间真是令人气愤,但至少它有效。
操作系统: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

墨离汐 2024-10-15 00:03:48

请检查您使用哪个用户帐户来执行我们的任务。您可能会使用与默认用户不同的用户运行任务,并且该用户需要一些额外的权限。
此外,也可能会发生任务已执行但您看不到任何效果,因为批处理文件等待某些用户响应,因此如果您看到进程正在运行,请检查任务管理器。
一旦我用 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.

赠意 2024-10-15 00:03:48
  1. 不要在 cmd/批处理文件中使用双引号
  2. 确保转到完整路径开始于(可选)
    C:\Necessary_file\Reqular_task\QDE\cmd_practice\

在此处输入图像描述

  1. Don't use double quotes in your cmd/batch file
  2. Make sure you go to the full path start in (optional):
    C:\Necessary_file\Reqular_task\QDE\cmd_practice\

enter image description here

一个人练习一个人 2024-10-15 00:03:48

尝试以高权限运行该任务。

在“开始于文件夹”中的路径末尾放置一个 \,例如 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.

公布 2024-10-15 00:03:48

操作:启动程序

程序/脚本: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 select Run only when user is logged on to see the window in action.

怂人 2024-10-15 00:03:48

就我而言,Windows 仅当我解决了两个“问题”时才同意执行脚本:

  1. 在主要执行之前,我必须将“cd C:/My_script_directory”放入脚本中。
  2. 在“程序/脚本”字段中,我放置了完整路径带有直斜杠,而不是反斜杠!
    “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":

  1. I had to put into my script "cd C:/My_script_directory" before main execution.
  2. In the "Program/script" field I've put the full path with straight slashes, not the back slahes!
    "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!

捎一片雪花 2024-10-15 00:03:47

我遇到了同样的问题,但我找到了另一个解决方案,而无需修改我的批处理脚本。

我唯一错过的是“操作”设置 - “开始于(可选)”选项。

转到任务属性-->操作选项卡 -->编辑-->填写如下:

  1. 操作:启动程序
  2. 程序/脚本:批处理脚本的路径,例如 C:\Users\beruk\bodo.bat
  3. 添加参数(可选):<如果需要 - 取决于您的脚本>
  4. 开始于(可选):输入批处理脚本位置的完整路径,例如 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:

  1. Action: Start a program
  2. Program/script: path to your batch script e.g. C:\Users\beruk\bodo.bat
  3. Add arguments (optional): <if necessary - depending on your script>
  4. Start in (optional): Put the full path to your batch script location e.g. C:\Users\beruk\(Do not put quotes around Start In)

Then Click OK

It works for me. Good Luck!

眼趣 2024-10-15 00:03:47

上述方法均无效。我按照教程中所说的方式尝试过,并且有效。

操作:

Start a program 

程序/脚本:

cmd

添加参数:

/c start "" "E:\Django-1.4.1\setup.bat"

在 Win7 Pro 上为我工作。您必须有一个有密码的帐户(空白密码不好)

None of the above method worked. I tried it this way as said it in a tutorial and it worked.

Action:

Start a program 

Program/script:

cmd

Add arguments:

/c start "" "E:\Django-1.4.1\setup.bat"

Worked for me on Win7 Pro. You must have an account with a password (blank passwords are no good)

冷心人i 2024-10-15 00:03:47

对于那些 bat 文件在 Windows 8 和 10+ 任务计划程序中仍然无法工作的人,我想在 Ghazi 的答案中添加一件事 - 在经历了很多痛苦之后:

  1. 在“操作”下,选择“创建 BASIC” 任务”,而不是“创建任务”

这对我来说是这样,加上其他不要忘记的问题:

  1. 如果需要,请在“启动程序”中使用引号>;程序/脚本条目,即“C:\my scripts\runme.bat”(或仅使用浏览按钮)...
  2. 使用批处理文件的开始路径,即使它显示可选 - 但不要在“开始于”字段中使用引号。 (疯狂但真实!)

这无需触发命令提示符即可工作。而且这是最快、最简单的方法。

(抱歉,我的代表太低,无法将我的基本任务提示添加到 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:

  1. Under Actions, Choose "Create BASIC task", not "Create Task"

That did it for me, plus the other issues not to forget:

  1. Use quotes, if you need to, in your Start a program > program/script entry i.e "C:\my scripts\runme.bat" (or just use the Browse button)...
  2. Use the Start In path to your batch file, even though it says optional - BUT DON'T use quotes in the Start In field. (Crazy but true!)

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)

忆依然 2024-10-15 00:03:47

确保“开始于”没有引号。

Make sure "Start In " has NO QUOTES.

风筝有风,海豚有海 2024-10-15 00:03:47

添加新文件夹中的任务


登录用户 vs 在后台运行


Add action


我的脚本是从 master 中提取最新代码并发布一个新分支

cd D:\dev\repo
git checkout master
git pull
git branch -D my-branch
git push origin --delete my-branch
git checkout -b my-branch
git push -u origin my-branch
exit

Add a new Task in a folder


Logged in user vs Running in background


Add action


My script was to pull latest code from master and publish a new branch

cd D:\dev\repo
git checkout master
git pull
git branch -D my-branch
git push origin --delete my-branch
git checkout -b my-branch
git push -u origin my-branch
exit
攒一口袋星星 2024-10-15 00:03:47

现在正在工作。这就是我所做的。您可能不需要所有这些步骤来使其工作,但只是为了确保尝试所有这些步骤:

  • 检查计划任务的帐户参数并确保它们设置为运行,无论是否有人登录到计算机

  • 检查以大多数特权/权限运行

  • 确保首先转到完整路径: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

执手闯天涯 2024-10-15 00:03:47

确保“开始于”不以反斜杠结尾。

Make sure "Start In" does NOT end with a BACKSLASH.

筑梦 2024-10-15 00:03:47

有一个问题,我的任务没有触发,只是因为它在没有电源线的笔记本电脑上运行...在“条件”选项卡下,默认情况下会选中它,以便在未连接交流电源时任务不会运行。

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.

最笨的告白 2024-10-15 00:03:47

在Windows7 Pro下,我发现Arun的解决方案对我有用:即使在“没有用户登录”的情况下我也可以让它工作,我确实选择了使用最高权限。

根据过去的经验,您必须拥有一个带有密码的帐户(空白密码不好),如果程序在完成向导时没有提示您输入密码,请返回并编辑一些内容,直到出现为止!

这是一种方法,以防不清楚哪种方法有效

Action: start a program
Program/script : cmd
      (doesn't need the .exe bit!)
Add arguments:
    /c start "" "E:\Django-1.4.1\setup.bat" 

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

Action: start a program
Program/script : cmd
      (doesn't need the .exe bit!)
Add arguments:
    /c start "" "E:\Django-1.4.1\setup.bat" 
兲鉂ぱ嘚淚 2024-10-15 00:03:47

我搞砸了几个小时并尝试了许多不同的建议。

我终于通过执行以下操作使其工作:

<块引用>

操作:启动程序

程序/脚本:C:\scriptdir\script.bat

添加参数(可选)script.bat

开始于(可选):c:\scriptdir

仅在用户登录时运行

以最高权限运行

配置:Windows Vista、Windows Server 2008

I messed with this for several hours and tried many different suggestions.

I finally got it to work by doing the following:

Action: Start a program

Program/Script: C:\scriptdir\script.bat

Add arguments (optional) script.bat

Start in (optional): c:\scriptdir

run only when user logged in

run with highest privileges

configure for: Windows Vista, Windows Server 2008

峩卟喜欢 2024-10-15 00:03:47

如果此处所有其余操作均失败,请确保您尝试运行任务的用户有权访问您尝试使用的文件。

就我而言,我尝试从 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文