How to run batch file from network share without "UNC path are not supported" message?
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
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?
PUSHD and POPD should help in your case.
@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
PUSHD /? from the command line for more information.
Read more... Read less...
There's a registry setting to avoid this security check (use it at your own risks, though):
Under the registry path
add the value DisableUNCCheck REG_DWORD and set the value to 0 x 1 (Hex).
Note: On Windows 10 version 1803, the setting seems to be located under HKLM: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor
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 @pushd %~dp0 ::::::::::::::::::: :: your script code here ::::::::::::::::::: @popd
pushd will change your working directory to the scripts location in the new mapped drive.
popd at the end, to clean up the mapped drive.
Basically, you can't run it from a UNC path without seeing that message.
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.
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
:: 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
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.
To delete the symbolic link, use the rmdir command.