如何从networking共享中运行batch file,而不需要“UNCpath不受支持”消息?

我试图从networking共享运行一个batch file,但我不断收到以下消息:“不支持UNCpath,默认Windows目录。 batch file位于\\Server\Soft\WPX5\install.bat 。 以pipe理员身份login时,从我的Windows 7桌面导航到\\Server\Soft\WP15\然后双击install.bat,即得到“UNCpath不受支持”。 信息。 我在网上发现了一些build议,指出映射驱动器将不起作用,但使用符号链接将解决这个问题,但符号链接并不适用于我。 下面是我的batch file内容,我将不胜感激任何帮助,可以帮助我完成我想要做的事情。 基本上,我希望能够从\\Server\Soft\WP15\install.bat运行batch file。

batch file内容

 mklink /d %userprofile%\Desktop\WP15 \\server\soft\WP15 \\server\soft\WP15\setup.exe robocopy.exe "\\server\soft\WP15\Custom" /copyall "C:\Program Files (x86)\WP\Custom Templates" Regedit.exe /s \\server\soft\WPX5\Custom\Migrate.reg 

另外,如何在安装完成后删除符号链接?

PUSHD和POPD应该帮助你的情况。

 @echo off :: Create a temporary drive letter mapped to your UNC root location :: and effectively CD to that location pushd \\server\soft :: Do your work WP15\setup.exe robocopy.exe "WP15\Custom" /copyall "C:\Program Files (x86)\WP\Custom Templates" Regedit.exe /s WPX5\Custom\Migrate.reg :: Remove the temporary drive letter and return to your original location popd 

typesPUSHD /? 从命令行获取更多信息。

有一个registry设置,以避免这种安全检查(使用它在你自己的风险,虽然):

在registrypath下

HKEY_CURRENT_USER
\软件
\微软
\命令处理器

添加值DisableUNCCheck REG_DWORD并将值设置为0 x 1(hex)。

基本上,您不能在没有看到该消息的情况下从UNCpath运行它。

我通常做的只是在脚本的顶部放置一个CLS ,所以我不必看到这个消息。 然后,指定您需要使用的networking共享中文件的完整path。

我需要能够通过Windows资源pipe理器浏览服务器共享,然后双击启动batch file。 @dbenham让我更容易解决我的情况(没有popd忧虑):

 :: Capture UNC or mapped-drive path script was launched from set NetPath=%~dp0 :: Assumes that setup.exe is in the same UNC path %NetPath%setup.exe :: Note that NetPath has a trailing backslash ("\") robocopy.exe "%NetPath%Custom" /copyall "C:\Program Files (x86)\WP\Custom Templates" Regedit.exe /s %NetPath%..\WPX5\Custom\Migrate.reg :: I am not sure if WPX5 was typo, so use ".." for parent directory set NetPath= pause 

我觉得cls是最好的答案。 它隐藏UNC消息之前,任何人都可以看到它。 我把它和一个@pushd %~dp0合并在一起,这样看起来好像是打开脚本并在一个步骤中映射位置,从而防止了进一步的UNC问题。

 cls @pushd %~dp0 ::::::::::::::::::: :: your script code here ::::::::::::::::::: @popd 

笔记:

pushd会将您的工作目录更改为新映射驱动器中的脚本位置。

popup最后,清理映射的驱动器。

而不是直接从资源pipe理器启动批处理 – 创build批处理的快捷方式,并将快捷方式属性中的起始目录设置为本地path,如%TEMP%或其他。

要删除符号链接,请使用rmdir命令。

我遇到了同样的问题,最近在Windows 7的networking共享驱动器上使用batch file。

另一种解决方法是通过Windows资源pipe理器将服务器映射到驱动器:工具 – >映射networking驱动器。 给它一个驱动器号和文件夹path\\ yourserver。 由于我的networking共享工作经常映射到它使得它更方便,并解决了“UNCpath不支持”的错误。

我的情况有点不同 我在启动时运行batch file来分发最新版本的内部业务应用程序。

在这种情况下,我正在使用以下string的Windowsregistry运行密钥

 cmd /c copy \\serverName\SharedFolder\startup7.bat %USERPROFILE% & %USERPROFILE%\startup7.bat 

这会以正确的顺序在启动时运行两个命令。 首先将batch file本地复制到用户有权访问的目录。 然后执行相同的batch file。 我可以创build一个本地目录c:\ InternalApps并复制networking中的所有文件。

解决原始海报的问题可能已经太晚了,但可能会帮助其他人。