unc 目录不受支持,CMD不支持将UNC路径作为当前目录

We have batch scripts that seem to run fine however I am editing one of them to include some new work and when manually running the script (by double-clicking from windows explorer) I get the above error message each time a pushd command in the script is encountered. These are pushd commands that have been there since the year dot and the scripts are running fine.

Is there a difference between the batch script running manually and when started by a scheduler?

How can I disable the error message when running manually (if this is possible)?

解决方案

On double clicking a batch file cmd.exe is started with implicit using option /C to close command process after finishing batch file execution and with setting directory of the batch file as current directory.

If the double clicked batch file is on a network share and UNC path is used instead of mapping the network share to a drive letter and use the network drive, cmd.exe informs the user that UNC path as current directory is not supported and sets %SystemRoot% (Windows directory) as current directory.

The warning can be ignored if the batch file is designed for being executed from any directory which means it does not require that the directory of the batch file is the current directory. Good coded batch files, especially those being executed by Windows task scheduler, can be executed with any directory being the current directory.

On running a batch file as scheduled task the task scheduler sets %SystemRoot%\System32 (Windows System directory) as current directory before executing the command, except a specific directory path is explicitly set as start in directory in properties of scheduled task.

Please note that when you enable support for running batch files with UNC path as current directory, some console applications could fail running because of not being designed for that environment.

In your case with batch file designed for execution as scheduled task and taking therefore all aspects into account as listed by me in answer on the question What must be taken into account on executing a batch file as scheduled task?, you can ignore this warning message on double clicking the batch file using UNC path.

Of course you can also create a shortcut file (*.lnk) for the batch file for starting the batch file via this shortcut with Start in in properties of shortcut file is set to %SystemRoot%\System32 as Windows task scheduler does by default.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值