Windows 任务计划程序不会 运行 ren 命令,但 cmd.exe 会

Windows Task Scheduler wont run ren command, but cmd.exe will

我正在创建一个为 ftp 上传执行批处理文件的任务。

批处理脚本只是将某个文件夹中的任何文件重命名为适当的名称,然后上传该文件夹。

我已将任务设置为服务帐户下的 运行,当我使用服务帐户登录并 运行 .bat 文件时,它可以完美运行。当我 运行 任务调度程序时,它 运行 是 .bat 文件,但日志显示 ren 命令不起作用。

这是通过任务调度程序调用后的日志输出:

c:\TEMP\Bulletin>rename "R:\x\x\x\*.pdf" Bulletin.pdf 

c:\TEMP\Bulletin>chdir c:\Program Files (x86)\WinSCP 

c:\Program Files (x86)\WinSCP>WinSCP.com /ini=nul /script=c:\TEMP\Bulletin\bulletin.tmp 
Searching for host...
Connecting to host...
Authenticating...
Using username "svc-bulletin".
Authenticating with pre-entered password.
Authenticated.
Starting the session...
Session started.
Active session: [1] svc-bulletin@x.x.x
File or folder 'C:\FileShares\Drive-R\x\x\x\Bulletin.pdf' does not exist.
System Error.  Code: 2.

The system cannot find the file specified
(A)bort, (R)etry, (S)kip, Ski(p) all: Abort

c:\Program Files (x86)\WinSCP>exit

这是手动调用 .bat 文件的输出:

C:\TEMP\Bulletin>rename "R:\x\x\x\*.pdf" Bulletin.pdf 

C:\TEMP\Bulletin>chdir c:\Program Files (x86)\WinSCP 

c:\Program Files (x86)\WinSCP>WinSCP.com /ini=nul /script=c:\TEMP\Bulletin\bulletin.tmp 
Searching for host...
Connecting to host...
Authenticating...
Using username "svc-bulletin".
Authenticating with pre-entered password.
Authenticated.
Starting the session...
Session started.
Active session: [1] svc-bulletin@x.x.x
C:\FileShares\Drive-R\x\x\x\Bulletin.pdf |         957 KB | 1390.5 KB/s | binary | 100%

c:\Program Files (x86)\WinSCP>exit

我运行正在使用完全权限执行该任务,并且还尝试在与 .bat 相同的目录中启动它,但没有,两者都不起作用。感谢任何 pointers/ideas.

我假设 R: 是映射驱动器。映射的驱动器是在用户登录时建立的,因为它们只为执行映射的用户映射。服务帐户对您帐户下映射的映射驱动器一无所知。使问题复杂化的是,根据您的任务设置,任务可能 运行 在 S4U 身份验证下,因此您将无法访问网络资源。这也消除了使用 UNC 而不是映射驱动器。参见 technet.microsoft.com/en-us/library/cc722152(v=ws.11).aspx