如何安排日常任务以运行批处理文件

如何安排日常任务以运行批处理文件

本文介绍了如何安排日常任务以运行批处理文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试安排Windows Server 2008上的任务以删除文件夹中的某些图像.我创建了一个批处理文件来执行此操作,我的代码如下:

I'm trying to schedule a task on Windows Server 2008 to delete some images on a folder. I create a batch file to execute this, my code below:

forfiles /s /m *.jpg /D -10 /C "cmd /c del @path"

(我没有放置目录,因为我将批处理文件存储在要删除图像的同一文件夹中,因此没有必要)

(I didn't put the dir because I store the batch file on the same folder where I want to erase the images, so it's no necesary)

我的问题是在尝试安排此任务以自动运行该任务时.因为当我手动运行此文件时,它成功擦除了图像,所以当我安排此任务并在管理员登录时根据条件运行该文件时,也会出现问题.当我指定运行该文件的条件时,系统将记录管理员或管理员.当然不是,并且具有很高的特权.我不知道为什么在这种情况下任务在我编程时就开始运行,但是却从不运行批处理文件,我可以在任务计划程序中看到我的任务正在运行,但是什么也没发生.有人有线索吗?

My issue is at the time I try to schedule this task to run this automatically. Because when I manually run this file IT ERASE THE IMAGES SUCCESSFULLY, also when I schedule this task with the condition to run it when the administrator is logged in. The problem comes when I specify the condition to run the file either the admin is logged or not and of course with high privileges. I don't know why in this case the task begins running at the time I programmed it, but it never runs the batch file, I can see at the task scheduler that my task is running but nothing's happening. Does somebody have a clue?

我包括了任务计划程序的屏幕截图:

I'm including the screenshots of the task scheduler:

推荐答案

即使没有用户登录也要计划运行任务时,工作目录将变为C:\Windows\system32.因此,您必须跳到正确的目录,否则将找不到文件.此外,您必须使用cd %~dp0而不是cd %CD%,因为%CD%仍将是system32文件夹,而%~dp0将是您的批处理文件所在的文件夹.

When scheduling tasks to run even if no user is logged on, the working directory becomes C:\Windows\system32. So you have to jump to the proper directory or otherwise the files won't be found. Further, you have to use cd %~dp0 and not cd %CD% as %CD% will still be the system32 folder whereas %~dp0 will be the folder your batch file is located in.

抱歉,我刚刚意识到 Squashman 已经给出了与评论相同的答案.

Sorry, I've just realized that Squashman has already given the same answer as a comment.

这篇关于如何安排日常任务以运行批处理文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 14:36