I am trying to run a batch file from a network share, but I keep getting the following message: "UNC path are not supported. Defaulting to Windows directory." The batch file is located on \\Server\Soft\WPX5\install.bat
. While logged in as administrator, from my Windows 7 Desktop, I navigate to \\Server\Soft\WP15\
and double click on install.bat, that's when I get the "UNC path are not supported." message. I found some suggestions online stating that mapping drive will not work, but using a symbolic link will solve this issue, but the symbolic link didn't work for me. Below is my batch file content, I would appreciate any assistance that can help me accomplish what I am trying to do. Basically, I want to be able to run the batch file from \\Server\Soft\WP15\install.bat
.
我正在尝试从一个网络共享运行一个批处理文件,但是我不断得到以下消息:“UNC路径不受支持。违约到Windows目录。”批处理文件位于\服务器\软\WPX5\安装.bat上。作为管理员登录时,我从Windows 7桌面导航到\Server\Soft\WP15\,双击install。bat,这时我得到“UNC路径不支持”消息。我在网上找到了一些建议,说映射驱动不能工作,但是使用符号链接可以解决这个问题,但是符号链接对我不起作用。下面是我的批处理文件内容,我将感谢任何能帮助我完成我正在尝试做的事情的帮助。基本上,我希望能够运行来自\Server\Soft\WP15\install.bat的批处理文件。
Batch file content
批处理文件的内容
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
Also, how do I remove the symbolic link after the install is completed?
另外,如何在安装完成后删除符号链接?
8 个解决方案
#1
113
PUSHD and POPD should help in your case.
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
Type PUSHD /?
from the command line for more information.
类型PUSHD / ?从命令行获取更多信息。
#2
18
There's a registry setting to avoid this security check (use it at your own risks, though):
有一个注册表设置可以避免这个安全检查(尽管您可以在自己的风险中使用它):
Under the registry path
注册表路径下
HKEY_CURRENT_USER
\Software
\Microsoft
\Command Processor微软HKEY_CURRENT_USER \ Software \ \命令处理器
add the value DisableUNCCheck REG_DWORD and set the value to 0 x 1 (Hex).
添加值DisableUNCCheck REG_DWORD并将值设置为0 x 1(十六进制)。
#3
8
Basically, you can't run it from a UNC path without seeing that message.
基本上,您不能在UNC路径上运行它而不看到该消息。
What I usually do is just put a CLS
at the top of the script so I don't have to see that message. Then, specify the full path to files in the network share that you need to use.
我通常做的是在脚本的顶部放一个CLS,这样我就不必看到那条消息了。然后,指定需要使用的网络共享中的文件的完整路径。
#4
7
I feel cls
is the best answer. It hides the UNC message before anyone can see it. I combined it with a @pushd %~dp0
right after so that it would seem like opening the script and map the location in one step, thus preventing further UNC issues.
我觉得cls是最好的答案。它在任何人看到UNC消息之前隐藏它。我将它与@pushd %~dp0结合在一起,这样看起来就像打开脚本并在一步中映射位置,从而防止了进一步的UNC问题。
cls
@pushd %~dp0
:::::::::::::::::::
:: your script code here
:::::::::::::::::::
@popd
Notes:
注:
pushd
will change your working directory to the scripts location in the new mapped drive.
pushd将把工作目录更改为新映射驱动器中的脚本位置。
popd
at the end, to clean up the mapped drive.
popd最后,清理映射驱动器。
#5
7
I needed to be able to just Windows Explorer browse through the server share, then double-click launch the batch file. @dbenham led me to an easier solution for my scenario (without the popd
worries):
我需要能够通过服务器共享浏览Windows资源管理器,然后双击启动批处理文件。@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
#6
3
Instead of launching the batch directly from explorer - create a shortcut to the batch and set the starting directory in the properties of the shortcut to a local path like %TEMP% or something.
不要直接从explorer启动批处理——创建批处理的快捷方式,并在快捷方式的属性中设置开始目录到本地路径,如%TEMP%或其他。
To delete the symbolic link, use the rmdir command.
要删除符号链接,请使用rmdir命令。
#7
1
I ran into the same issue recently working with a batch file on a network share drive in Windows 7.
最近,我在Windows 7的网络共享驱动器上处理一个批处理文件时遇到了同样的问题。
Another way that worked for me was to map the server to a drive through Windows Explorer: Tools -> Map network drive. Give it a drive letter and folder path to \yourserver. Since I work with the network share often mapping to it makes it more convenient, and it resolved the “UNC path are not supported” error.
另一种对我有用的方法是通过Windows Explorer将服务器映射到驱动器:Tools ->映射网络驱动器。给它一个驱动器信和文件夹路径到你的服务器。由于我与网络共享一起工作,经常映射到它使它更方便,并且它解决了“UNC路径不支持”错误。
#8
1
My situation is just a little different. I'm running a batch file on startup to distribute the latest version of internal business applications.
我的情况有点不同。我正在启动时运行一个批处理文件来分发最新版本的内部业务应用程序。
In this situation I'm using the Windows Registry Run Key with the following string
在这种情况下,我使用Windows注册表运行键,并使用以下字符串
cmd /c copy \\serverName\SharedFolder\startup7.bat %USERPROFILE% & %USERPROFILE%\startup7.bat
This runs two commands on startup in the correct sequence. First copying the batch file locally to a directory the user has permission to. Then executing the same batch file. I can create a local directory c:\InternalApps and copy all of the files from the network.
这将以正确的顺序在启动时运行两个命令。首先,将批处理文件本地复制到用户具有权限的目录。然后执行相同的批处理文件。我可以创建一个本地目录c:\InternalApps并从网络中复制所有文件。
This is probably too late to solve the original poster's question but it may help someone else.
这可能太晚了,无法解决最初海报的问题,但它可能会帮助其他人。
#1
113
PUSHD and POPD should help in your case.
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
Type PUSHD /?
from the command line for more information.
类型PUSHD / ?从命令行获取更多信息。
#2
18
There's a registry setting to avoid this security check (use it at your own risks, though):
有一个注册表设置可以避免这个安全检查(尽管您可以在自己的风险中使用它):
Under the registry path
注册表路径下
HKEY_CURRENT_USER
\Software
\Microsoft
\Command Processor微软HKEY_CURRENT_USER \ Software \ \命令处理器
add the value DisableUNCCheck REG_DWORD and set the value to 0 x 1 (Hex).
添加值DisableUNCCheck REG_DWORD并将值设置为0 x 1(十六进制)。
#3
8
Basically, you can't run it from a UNC path without seeing that message.
基本上,您不能在UNC路径上运行它而不看到该消息。
What I usually do is just put a CLS
at the top of the script so I don't have to see that message. Then, specify the full path to files in the network share that you need to use.
我通常做的是在脚本的顶部放一个CLS,这样我就不必看到那条消息了。然后,指定需要使用的网络共享中的文件的完整路径。
#4
7
I feel cls
is the best answer. It hides the UNC message before anyone can see it. I combined it with a @pushd %~dp0
right after so that it would seem like opening the script and map the location in one step, thus preventing further UNC issues.
我觉得cls是最好的答案。它在任何人看到UNC消息之前隐藏它。我将它与@pushd %~dp0结合在一起,这样看起来就像打开脚本并在一步中映射位置,从而防止了进一步的UNC问题。
cls
@pushd %~dp0
:::::::::::::::::::
:: your script code here
:::::::::::::::::::
@popd
Notes:
注:
pushd
will change your working directory to the scripts location in the new mapped drive.
pushd将把工作目录更改为新映射驱动器中的脚本位置。
popd
at the end, to clean up the mapped drive.
popd最后,清理映射驱动器。
#5
7
I needed to be able to just Windows Explorer browse through the server share, then double-click launch the batch file. @dbenham led me to an easier solution for my scenario (without the popd
worries):
我需要能够通过服务器共享浏览Windows资源管理器,然后双击启动批处理文件。@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
#6
3
Instead of launching the batch directly from explorer - create a shortcut to the batch and set the starting directory in the properties of the shortcut to a local path like %TEMP% or something.
不要直接从explorer启动批处理——创建批处理的快捷方式,并在快捷方式的属性中设置开始目录到本地路径,如%TEMP%或其他。
To delete the symbolic link, use the rmdir command.
要删除符号链接,请使用rmdir命令。
#7
1
I ran into the same issue recently working with a batch file on a network share drive in Windows 7.
最近,我在Windows 7的网络共享驱动器上处理一个批处理文件时遇到了同样的问题。
Another way that worked for me was to map the server to a drive through Windows Explorer: Tools -> Map network drive. Give it a drive letter and folder path to \yourserver. Since I work with the network share often mapping to it makes it more convenient, and it resolved the “UNC path are not supported” error.
另一种对我有用的方法是通过Windows Explorer将服务器映射到驱动器:Tools ->映射网络驱动器。给它一个驱动器信和文件夹路径到你的服务器。由于我与网络共享一起工作,经常映射到它使它更方便,并且它解决了“UNC路径不支持”错误。
#8
1
My situation is just a little different. I'm running a batch file on startup to distribute the latest version of internal business applications.
我的情况有点不同。我正在启动时运行一个批处理文件来分发最新版本的内部业务应用程序。
In this situation I'm using the Windows Registry Run Key with the following string
在这种情况下,我使用Windows注册表运行键,并使用以下字符串
cmd /c copy \\serverName\SharedFolder\startup7.bat %USERPROFILE% & %USERPROFILE%\startup7.bat
This runs two commands on startup in the correct sequence. First copying the batch file locally to a directory the user has permission to. Then executing the same batch file. I can create a local directory c:\InternalApps and copy all of the files from the network.
这将以正确的顺序在启动时运行两个命令。首先,将批处理文件本地复制到用户具有权限的目录。然后执行相同的批处理文件。我可以创建一个本地目录c:\InternalApps并从网络中复制所有文件。
This is probably too late to solve the original poster's question but it may help someone else.
这可能太晚了,无法解决最初海报的问题,但它可能会帮助其他人。