Windows批处理文件 - 移动文件仅在任务计划程序中不起作用

时间:2022-06-14 05:37:54

I have a file that I'm try to move via a batch file on a timed schedule.

我有一个文件,我试图通过定时计划中的批处理文件移动。

move sourceFile destinationFile.

移动sourceFile destinationFile。

Destination file is on a mapped network drive Z.

目标文件位于映射的网络驱动器Z上。

So for example, the command would be:

例如,命令将是:

move C:\myfile.txt Z:\myfile.txt

移动C:\ myfile.txt Z:\ myfile.txt

When I execute the batch file in Windows by double clicking it, it works fine. But when I schedule it via Task Scheduler, it doesn't work.

当我通过双击它在Windows中执行批处理文件时,它工作正常。但是,当我通过任务计划程序安排它时,它不起作用。

I added in:

我补充说:

net use Z: \myipaddress

净使用Z:\ myipaddress

to see if the problem was a resolution issue, but this also works only with the batch file directly, not in Task Scheduler.

查看问题是否是解决问题,但这也只适用于批处理文件,而不适用于任务计划程序。

The task is running with the highest privileges as Administrator.

该任务以管理员的最高权限运行。

OS = Windows 2008 server.

OS = Windows 2008服务器。

Any ideas?

Thanks.

5 个解决方案

#1


I found the answer: go into the properties of the task and UNCHECK "Run with highest privileges" and it will work.

我找到了答案:进入任务的属性和UNCHECK“以最高权限运行”,它将起作用。

Richard's answer prompted me to look into this more. I ran cmd as administrator, couldn't find my mapped drive. Therefore, the task scheduler cannot find it when it runs as administrator, which "highest privileges" is doing.

理查德的回答促使我更多地研究这个问题。我以管理员身份运行cmd,找不到我的映射驱动器。因此,任务调度程序在以管理员身份运行时无法找到它,“最高权限”正在执行。

#2


"The task is running with the highest privileges as Administrator." reminded me of something, this happened in Vista and still happens in Windows 7 (I've just upgraded): I've found that my mapped network drives aren't available when I run a command prompt as administrator.

“该任务以管理员的最高权限运行。”提醒我一些事情,这发生在Vista中,仍然发生在Windows 7中(我刚刚升级):我发现当我以管理员身份运行命令提示符时,我的映射网络驱动器不可用。

You might want to try running your batch file from within an elevated (Administrator) command prompt and see whether you get the same error, I suspect you will.

您可能希望尝试从提升(管理员)命令提示符中运行批处理文件,看看是否会出现相同的错误,我怀疑您会这样做。

You might be able to schedule the command "move" instead as the scheduled task to run and pass it the "C:\myfile.txt Z:\myfile.txt" parameters? (I haven't tried this)

您可以将命令“move”安排为运行的计划任务,并将其传递给“C:\ myfile.txt Z:\ myfile.txt”参数? (我没试过这个)

#3


This sounds like an authentication issue - are you sure the user that's running the task has admin rights (or the same rights as the user logged in when 'it works')?

这听起来像是一个身份验证问题 - 您确定运行该任务的用户具有管理员权限(或者与“工作时”用户登录时相同的权限)吗?

#4


I'm not exactly sure what the problem is, but you can help yourself a bit by changing your batch file a bit and adding some output logging:

我不确定问题是什么,但您可以通过稍微更改批处理文件并添加一些输出日志记录来帮助自己:

net use z: \\ipaddress\shared_folder >c:\debug_log.txt 2>&1
move c:\myfile.txt z:\myfile.txt >>c:\debug_log.txt 2>&1

After the scheduled task runs, you should be able to review c:\debug_log.txt for all output and errors those two command produced.

计划任务运行后,您应该能够查看c:\ debug_log.txt以查看这两个命令生成的所有输出和错误。

#5


Have you tried using UNC style paths instead of mapped drives?

您是否尝试过使用UNC样式路径而不是映射驱动器?

something like (untested):

像(未经测试的):

move \\server\share\file_path \\other_server\other_share\new_file_path 

#1


I found the answer: go into the properties of the task and UNCHECK "Run with highest privileges" and it will work.

我找到了答案:进入任务的属性和UNCHECK“以最高权限运行”,它将起作用。

Richard's answer prompted me to look into this more. I ran cmd as administrator, couldn't find my mapped drive. Therefore, the task scheduler cannot find it when it runs as administrator, which "highest privileges" is doing.

理查德的回答促使我更多地研究这个问题。我以管理员身份运行cmd,找不到我的映射驱动器。因此,任务调度程序在以管理员身份运行时无法找到它,“最高权限”正在执行。

#2


"The task is running with the highest privileges as Administrator." reminded me of something, this happened in Vista and still happens in Windows 7 (I've just upgraded): I've found that my mapped network drives aren't available when I run a command prompt as administrator.

“该任务以管理员的最高权限运行。”提醒我一些事情,这发生在Vista中,仍然发生在Windows 7中(我刚刚升级):我发现当我以管理员身份运行命令提示符时,我的映射网络驱动器不可用。

You might want to try running your batch file from within an elevated (Administrator) command prompt and see whether you get the same error, I suspect you will.

您可能希望尝试从提升(管理员)命令提示符中运行批处理文件,看看是否会出现相同的错误,我怀疑您会这样做。

You might be able to schedule the command "move" instead as the scheduled task to run and pass it the "C:\myfile.txt Z:\myfile.txt" parameters? (I haven't tried this)

您可以将命令“move”安排为运行的计划任务,并将其传递给“C:\ myfile.txt Z:\ myfile.txt”参数? (我没试过这个)

#3


This sounds like an authentication issue - are you sure the user that's running the task has admin rights (or the same rights as the user logged in when 'it works')?

这听起来像是一个身份验证问题 - 您确定运行该任务的用户具有管理员权限(或者与“工作时”用户登录时相同的权限)吗?

#4


I'm not exactly sure what the problem is, but you can help yourself a bit by changing your batch file a bit and adding some output logging:

我不确定问题是什么,但您可以通过稍微更改批处理文件并添加一些输出日志记录来帮助自己:

net use z: \\ipaddress\shared_folder >c:\debug_log.txt 2>&1
move c:\myfile.txt z:\myfile.txt >>c:\debug_log.txt 2>&1

After the scheduled task runs, you should be able to review c:\debug_log.txt for all output and errors those two command produced.

计划任务运行后,您应该能够查看c:\ debug_log.txt以查看这两个命令生成的所有输出和错误。

#5


Have you tried using UNC style paths instead of mapped drives?

您是否尝试过使用UNC样式路径而不是映射驱动器?

something like (untested):

像(未经测试的):

move \\server\share\file_path \\other_server\other_share\new_file_path