Windows 批处理文件 - 移动文件仅在任务计划程序中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1019263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Windows Batch File - Move File not working in Task Scheduler only
提问by
I have a file that I'm try to move via a batch file on a timed schedule.
我有一个文件,我尝试按定时计划通过批处理文件移动该文件。
move 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.
操作系统 = Windows 2008 服务器。
Any ideas?
有任何想法吗?
Thanks.
谢谢。
回答by Matt
I found the answer: go into the properties of the task and UNCHECK "Run with highest privileges" and it will work.
我找到了答案:进入任务的属性并取消选中“以最高权限运行”,它将起作用。
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,找不到我的映射驱动器。因此,任务调度器在以管理员身份运行时找不到它,这是“最高权限”所做的。
回答by Richard Lucas
"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”参数?(这个我没试过)
回答by Grant Wagner
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
这两个命令产生的所有输出和错误。
回答by JohnIdol
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')?
这听起来像是一个身份验证问题 - 您确定运行任务的用户具有管理员权限(或与“它工作”时登录的用户具有相同的权限)?
回答by Zenshai
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