pushd不允许UNC路径,启用cmd扩展

时间:2017-01-30 20:43:03

标签: windows batch-file cmd unc

我已经使用pushd "%~dp0" trick多年来从服务器位置运行批处理文件而没有问题。它不再起作用了,并不是因为CMD扩展程序不可用或我已用完驱动器号(ref1ref2)。有什么线索是怎么回事?

系统是Win7-Pro SP1 x64。

与CMD互动或修改CMD的第三方安装(我非常确定我在安装后使用了pushd + UNC,这是一种非常常见的技术,但不能发誓它):

d:\>pushd \\server4\share
' '
CMD does not support UNC paths as current directories.

d:\>reg query "HKCU\Software\Microsoft\Command Processor" /v EnableExtensions

HKEY_CURRENT_USER\Software\Microsoft\Command Processor
    EnableExtensions    REG_DWORD    0x1

d:\>net use
New connections will be remembered.

Status       Local     Remote                    Network
-------------------------------------------------------------------------------
OK           B:        \\server1\dev              Microsoft Windows Network
OK           F:        \\server1\dev              Microsoft Windows Network
OK           G:        \\server2\corp             Microsoft Windows Network
OK           H:        \\server3\home             Microsoft Windows Network
OK           I:        \\server4\share            Microsoft Windows Network
OK           N:        \\server1\dev              Microsoft Windows Network
OK           O:        \\server1\dev              Microsoft Windows Network
OK           P:        \\server5\files            Microsoft Windows Network
OK           Q:        \\server1\dev              Microsoft Windows Network
OK           R:        \\server5\work             Microsoft Windows Network
             S:        \\server6\data             Microsoft Windows Network
OK           T:        \\server5\maps             Microsoft Windows Network
OK           U:        \\server7\layers           Microsoft Windows Network
OK           V:        \\server8\home\me          Microsoft Windows Network
OK           W:        \\server5\warehouse        Microsoft Windows Network
OK           X:        \\server5\work             Microsoft Windows Network
OK           Y:        \\server5\dev_repo         Microsoft Windows Network
OK           Z:        \\server5\repository       Microsoft Windows Network
OK                     \\server5\work             Microsoft Windows Network
                       \\mysites.sharepoint.org\DavWWWRoot  Web Client Network
OK                     \\server4\ITSupport        Microsoft Windows Network
                       \\sharepoint.org@SSL\DavWWWRoot  Web Client Network
                       \\sharepoint.org\DavWWWRoot      Web Client Network

The command completed successfully.

2 个答案:

答案 0 :(得分:0)

想出来!我是驱动器号中的,但不是来自映射驱动器或本地驱动器。我有一个带有集成USB集线器的戴尔显示器,它预先分配驱动器字母J:到L:即使没有插入设备。我使用它们很少我忘记了所有这些。

导致我发现的是删除所有非必要的映射驱动器并重复pushd \\server\share直到错误发生,注意它总是跳过一些驱动器号,然后看看磁盘管理。

D:\>pushd \\server\share

Q:\>pushd \\server\share

O:\>pushd \\server\share

N:\>pushd \\server\share

F:\>pushd \\server\share

B:\>pushd \\server\share
' '
CMD does not support UNC paths as current directories.

Disk Management showing pre-allocated USB drive letters

答案 1 :(得分:0)

我可以在net use输出中看到相同UNC路径的多个临时驱动器映射,例如\\server1\dev

OK           B:        \\server1\dev              Microsoft Windows Network
OK           F:        \\server1\dev              Microsoft Windows Network
OK           N:        \\server1\dev              Microsoft Windows Network
OK           O:        \\server1\dev              Microsoft Windows Network
OK           Q:        \\server1\dev              Microsoft Windows Network

请注意popd与链接的pushd "%~dp0" trick中的pushd一起使用:

@echo off

    :: Create a temporary drive letter mapped to your UNC root location
    ::                          and effectively CD to that location
pushd "%~dp0"

    :: Do your work
       :: launch executables directly
something.exe parameters
       :: aternatively, launch executables using START
start "" something.exe parameters

       :: IMPORTANT! launch batch files using CALL command
       ::            to return from a called script to the calling one
CALL something.BAT parameters
CALL something.CMD parameters

    :: Remove the temporary drive letter and return to your original location
POPD