Windows Scheduler没有执行批处理脚本,但是脚本可以从命令行正常运行 [英] Windows scheduler isn't executing the batch script,but script works fine from command line

查看:83
本文介绍了Windows Scheduler没有执行批处理脚本,但是脚本可以从命令行正常运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用今天的日期作为文件夹名称来创建文件夹.然后,我想将数据从远程计算机移至新创建的文件夹.

我写了一个看起来像这样的批处理脚本

我的批处理脚本.
名称:run.bat

  :: @ ECHO关闭SET CurrentDate =%date:〜-4,4%_%date:〜-10,2%_%date:〜7.2%SET CurrentDate =%CurrentDate:=%%SystemRoot%\ System32 \ cmd.exe"/c mkdir"Z:\ some_name_commercial \%CurrentDate%"C:\ Users \ H213561 \ Documents \ pscp.exe -l用户名-pw **** username@mftp.somename.com:/Distribution/somename_corp/*"Z:\ some_name_commercial \%CurrentDate%" 

脚本运行正常,当我从命令行运行上述脚本时,它可以完成我打算做的事情.但是我无法在Windows Scheduler中安排脚本作为日常工作.

我尝试了什么!

我认为问题出在mkdir命令上,我试图给出完整的路径就像没有运气一样.

 %SystemRoot%\ System32 \ cmd.exe"/c mkdir"Z:\ some_name_commercial \%CurrentDate%" 

P.S:Z:\是已安装的NAS(网络驱动器)

更新:

当我的目标位置不是网络驱动器时,我可以使它工作.但是,如果它是网络驱动器,则任务计划程序将无法正常工作.

解决方案

计划的任务可以根据您的设置在不同的会话"中运行.

例如,如果您具有仅在用户登录时运行"

然后,您可以看到计划的任务将与用户在同一会话中运行.如果用户未登录,则该任务将不会运行.该任务将看到用户的所有驱动器映射

如果设置为无论用户是否登录都运行",

然后,该过程在另一个会话中运行,即所谓的-

在这种模式下,任务看不到用户的驱动器映射.

(1)选项1一种方法是在任务中明确映射驱动器

例如

  net use Z:/删除净使用Z:<共享名称> 

然后您的其余任务可以与Z一起使用:

(2)选项2

始终使用标准路径,即 \\服务器名称\共享名称\文件夹名称

在大多数情况下,无论用户是否登录,都希望任务运行.在这种情况下,您不应该检查以下内容:

I want to create folder with todays date as the name of folder. Then, I want to move the data from remote machine to the newly created folder.

I have written a batch script which looks like

My batch script.
name: run.bat

::@ECHO off
SET CurrentDate= %date:~-4,4%_%date:~-10,2%_%date:~7,2%
SET CurrentDate=%CurrentDate: =%
"%SystemRoot%\System32\cmd.exe"  /c mkdir  "Z:\some_name_commercial\%CurrentDate%"
C:\Users\H213561\Documents\pscp.exe -l username -pw **** username@mftp.somename.com:/Distribution/somename_corp/*  "Z:\some_name_commercial\%CurrentDate%"

The script is working fine, When I run the above script from command line it does what I intend to do. But I am unable to schedule the script in windows scheduler as a daily job.

what I tried!!!

I think the problem is with mkdir command, I tried giving a complete path like with no luck.

"%SystemRoot%\System32\cmd.exe"  /c mkdir  "Z:\some_name_commercial\%CurrentDate%"

P.S : Z:\ is the mounted NAS (network drive)

Update:

I am able to get this working, when my destination location is not a network drive. But task scheduler doesnt work, if it is a network drive.

解决方案

The scheduled tasks can run in "different sessions" based on your setting.

For e.g., if you have "Run only when the user is logged on"

then, you can see that the scheduled tasks would run in the same session as the user. The task will NOT run if the user is NOT logged on. The task will see all the drive mappings of the user

If setting is "Run whether user is logged on or not",

then, the process runs in a different session, the so called - session 0

In this mode, the task can not see the user's drive mappings.

(1) Option 1 One way is to explicitly map the drive in your task

eg.

net use Z: /delete
net use Z: <share name>

Then the rest of your task can work with Z:

(2) Option 2

Always use the fully qualified path, i.e., \\server name\share name\folder name

In most cases, you would want the task to run irrespective of whether the user is logged in or not. In that case, you should not check this:

这篇关于Windows Scheduler没有执行批处理脚本,但是脚本可以从命令行正常运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆