Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 \\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?

like image 534
Stew Avatar asked Jan 26 '12 04:01

Stew


People also ask

How do I fix UNC path is not supported?

If you open a file with such a path, the program will crash when you try to import a glazing system. You can solve this problem by mapping a normal drive letter to the path that has the UNC path.

How do I find the UNC path of a network drive?

In Windows, if you have mapped network drives and you don't know the UNC path for them, you can start a command prompt (Start → Run → cmd.exe) and use the net use command to list your mapped drives and their UNC paths: C:\>net use New connections will be remembered.

How do I specify UNC path?

A UNC path uses double slashes or backslashes to precede the name of the computer. The path (disk and directories) within the computer are separated with a single slash or backslash, as in the following examples. Note that in the DOS/Windows example, drive letters (c:, d:, etc.) are not used in UNC names.

How do you get UNC path of a file?

to get the UNC path you don't need any code. There you should see the shared folders of the computer (share name and location). Just replace the <computername> with the name of your computer with the file.


2 Answers

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 

Type PUSHD /? from the command line for more information.

like image 157
dbenham Avatar answered Oct 20 '22 01:10

dbenham


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 @pushd %~dp0 ::::::::::::::::::: :: your script code here ::::::::::::::::::: @popd 

Notes:

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.

like image 34
Grallen Avatar answered Oct 19 '22 23:10

Grallen