使用Windows任务调度程序运行批处理文件

时间:2022-05-04 00:15:56

I have a batch file daily.bat, this is the code:

我每天都有批处理文件。bat,这是密码:

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.

我在Windows 7中创建了一个任务调度程序。当我手动运行批处理时,一切正常,但是当我尝试使用任务调度程序运行它时,什么也没有发生。

My action is

我的行动是

'run script' "C:\inetpub\wwwroot\site\x\cron\daily.bat"

UAC is off and I am Admin.

UAC关闭了,我是管理员。

Any idea why this is not working?

你知道为什么这行不通吗?

14 个解决方案

#1


211  

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. 行动:开始一个项目
  3. Program/script: path to your batch script e.g. C:\Users\beruk\bodo.bat
  4. 程序/脚本:批处理脚本路径例如C:\Users\beruk\bodo.bat
  5. Add arguments (optional): <if necessary - depending on your script>
  6. 添加参数(可选): <必要时——取决于您的脚本> 。
  7. Start in (optional): Put the full path to your batch script location e.g. C:\Users\beruk\(Do not put quotes around Start In)
  8. 开始(可选):把你的批处理脚本的完整路径位置如C:\Users\beruk\(不要把引号开始)

Then Click OK

然后单击OK

It works for me. Good Luck!

它适合我。好运!

#2


40  

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

程序/脚本:cmd

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

添加参数:/c开始"" 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)

在Win7 Pro上为我工作。你必须有一个有密码的账号(空白密码不好)

#3


35  

For those whose bat files are still not working in Windows 8+ Task Scheduler , one thing I would like to add to Ghazi's answer - after much suffering:

对于那些在Windows 8+任务调度器中仍然不能使用bat文件的人,我想补充一点,在经历了很多痛苦之后,Ghazi的答案是:

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

1)在Actions选项下,选择“创建基本任务”,而不是“创建任务”

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

这一切都是为了我,还有其他的一些问题:

  1. Use the Start In path to your batch file, even though it says optional
  2. 在批处理文件的路径中使用Start,即使它是可选的
  3. use quotes, if you need to, in your Start a program > program/script entry i.e "C:\my scripts\runme.bat" ...
  4. 如果需要,请使用引号在启动程序>程序/脚本条目i中。e " C:\ \ runme我的脚本。蝙蝠”…
  5. BUT DON'T use quotes in your Start in field. (Crazy but true!)
  6. 但是不要在开始的时候使用引号。(疯狂但真的!)

This worked without any need to trigger a command prompt.

这在不需要触发命令提示符的情况下工作。

(Sorry my rep is too low to add my Basic Task tip to Ghazi's comments)

(对不起,我的代表太低了,无法在Ghazi的评论中添加我的基本任务提示)

#4


18  

Make sure "Start In " has NO QUOTES.

确保“开始”没有引号。

#5


7  

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

    确保你走完整的路线: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

    超级管理员,输入“Net user administrator /active:yes”在命令提示中,注销并登录为超级管理员,所以UAC关闭了。

#6


5  

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.

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

#7


3  

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.

在Windows7 Pro下,我发现Arun的解决方案对我很有效:即使“没有用户登录”,我也能让它正常工作,我的确选择了使用最高的priveledge。

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" 

#8


2  

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

确保“开始”不是以反斜线结束。

#9


2  

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

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

Add arguments (optional) script.bat

(可选)script.bat添加参数

Start in (optional): c:\scriptdir

开始(可选):c:\ scriptdir

run only when user logged in

只有用户登录时才运行

run with highest privileges

使用最高权限运行

configure for: Windows Vista, Windows Server 2008

配置为:Windows Vista, Windows Server 2008

#10


2  

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.

在我的例子中我试图运行一个批处理文件从C:\Users\管理员\帐户不能访问桌面。将它移动到C上的一个中立位置:\解决了这个问题。

#11


1  

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.

请检查您使用哪个用户帐户执行我们的任务。您可能会在运行任务时使用不同的用户而不是默认用户,这个用户需要一些额外的特权。也可能执行任务,但您看不到任何效果,因为批处理文件等待一些用户响应,因此,如果您看到进程正在运行,请检查任务管理器。一旦发生,我就会安排一些web页面的svn更新,并且进程挂起,因为svn要求接受服务器证书。

#12


1  

  1. Don't use double quotes in your cmd/batch file
  2. 不要在cmd/批处理文件中使用双引号
  3. Make sure you go to the full path start in (optional):
    C:\Necessary_file\Reqular_task\QDE\cmd_practice\
  4. 确保你进入完整的路径开始(可选):C:\Necessary_file\Reqular_task\QDE\cmd_practice\

使用Windows任务调度程序运行批处理文件

#13


0  

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

使用任务调度器主窗口中的Run按钮来测试几个变体,最终找到了正确的设置。这两个选项必须结合使用:-仅当用户登录时才运行——以最高的权限运行。所有其他的变化失败了。浪费在这上面的所有时间都让人愤怒,但至少它起作用了。操作系统:WINDOWS 8核心(基本)版本

#14


0  

Try run the task with high privileges.

尝试使用高权限运行任务。

put a \ at the end of path in "start in folder" such as c:\temp\

在“开始文件夹”(例如c:\temp\)中,在路径的末端放置一个\

I do not know why , but this works for me sometimes.

我不知道为什么,但这有时对我有用。

#1


211  

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. 行动:开始一个项目
  3. Program/script: path to your batch script e.g. C:\Users\beruk\bodo.bat
  4. 程序/脚本:批处理脚本路径例如C:\Users\beruk\bodo.bat
  5. Add arguments (optional): <if necessary - depending on your script>
  6. 添加参数(可选): <必要时——取决于您的脚本> 。
  7. Start in (optional): Put the full path to your batch script location e.g. C:\Users\beruk\(Do not put quotes around Start In)
  8. 开始(可选):把你的批处理脚本的完整路径位置如C:\Users\beruk\(不要把引号开始)

Then Click OK

然后单击OK

It works for me. Good Luck!

它适合我。好运!

#2


40  

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

程序/脚本:cmd

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

添加参数:/c开始"" 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)

在Win7 Pro上为我工作。你必须有一个有密码的账号(空白密码不好)

#3


35  

For those whose bat files are still not working in Windows 8+ Task Scheduler , one thing I would like to add to Ghazi's answer - after much suffering:

对于那些在Windows 8+任务调度器中仍然不能使用bat文件的人,我想补充一点,在经历了很多痛苦之后,Ghazi的答案是:

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

1)在Actions选项下,选择“创建基本任务”,而不是“创建任务”

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

这一切都是为了我,还有其他的一些问题:

  1. Use the Start In path to your batch file, even though it says optional
  2. 在批处理文件的路径中使用Start,即使它是可选的
  3. use quotes, if you need to, in your Start a program > program/script entry i.e "C:\my scripts\runme.bat" ...
  4. 如果需要,请使用引号在启动程序>程序/脚本条目i中。e " C:\ \ runme我的脚本。蝙蝠”…
  5. BUT DON'T use quotes in your Start in field. (Crazy but true!)
  6. 但是不要在开始的时候使用引号。(疯狂但真的!)

This worked without any need to trigger a command prompt.

这在不需要触发命令提示符的情况下工作。

(Sorry my rep is too low to add my Basic Task tip to Ghazi's comments)

(对不起,我的代表太低了,无法在Ghazi的评论中添加我的基本任务提示)

#4


18  

Make sure "Start In " has NO QUOTES.

确保“开始”没有引号。

#5


7  

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

    确保你走完整的路线: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

    超级管理员,输入“Net user administrator /active:yes”在命令提示中,注销并登录为超级管理员,所以UAC关闭了。

#6


5  

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.

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

#7


3  

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.

在Windows7 Pro下,我发现Arun的解决方案对我很有效:即使“没有用户登录”,我也能让它正常工作,我的确选择了使用最高的priveledge。

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" 

#8


2  

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

确保“开始”不是以反斜线结束。

#9


2  

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

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

Add arguments (optional) script.bat

(可选)script.bat添加参数

Start in (optional): c:\scriptdir

开始(可选):c:\ scriptdir

run only when user logged in

只有用户登录时才运行

run with highest privileges

使用最高权限运行

configure for: Windows Vista, Windows Server 2008

配置为:Windows Vista, Windows Server 2008

#10


2  

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.

在我的例子中我试图运行一个批处理文件从C:\Users\管理员\帐户不能访问桌面。将它移动到C上的一个中立位置:\解决了这个问题。

#11


1  

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.

请检查您使用哪个用户帐户执行我们的任务。您可能会在运行任务时使用不同的用户而不是默认用户,这个用户需要一些额外的特权。也可能执行任务,但您看不到任何效果,因为批处理文件等待一些用户响应,因此,如果您看到进程正在运行,请检查任务管理器。一旦发生,我就会安排一些web页面的svn更新,并且进程挂起,因为svn要求接受服务器证书。

#12


1  

  1. Don't use double quotes in your cmd/batch file
  2. 不要在cmd/批处理文件中使用双引号
  3. Make sure you go to the full path start in (optional):
    C:\Necessary_file\Reqular_task\QDE\cmd_practice\
  4. 确保你进入完整的路径开始(可选):C:\Necessary_file\Reqular_task\QDE\cmd_practice\

使用Windows任务调度程序运行批处理文件

#13


0  

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

使用任务调度器主窗口中的Run按钮来测试几个变体,最终找到了正确的设置。这两个选项必须结合使用:-仅当用户登录时才运行——以最高的权限运行。所有其他的变化失败了。浪费在这上面的所有时间都让人愤怒,但至少它起作用了。操作系统:WINDOWS 8核心(基本)版本

#14


0  

Try run the task with high privileges.

尝试使用高权限运行任务。

put a \ at the end of path in "start in folder" such as c:\temp\

在“开始文件夹”(例如c:\temp\)中,在路径的末端放置一个\

I do not know why , but this works for me sometimes.

我不知道为什么,但这有时对我有用。