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?
Borealid
95.5k9 gold badges106 silver badges122 bronze badges
asked Jan 26, 2012 at 4:27
2
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.
answered Jan 26, 2012 at 15:48
dbenhamdbenham
128k28 gold badges254 silver badges391 bronze badges
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
@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.
answered Dec 9, 2015 at 15:10
GrallenGrallen
1,6201 gold badge17 silver badges16 bronze badges
5
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 Processoradd 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
answered Jan 11, 2013 at 12:18
VinzzVinzz
3,9686 gold badges36 silver badges51 bronze badges
3
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.
answered Jan 26, 2012 at 13:03
aphoriaaphoria
19.8k8 gold badges64 silver badges73 bronze badges
3
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):
:: 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
answered Oct 25, 2014 at 16:52
1
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.
answered Jan 26, 2012 at 13:47
2
I ran into the same issue recently working with a batch file on a network share drive in 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.
answered Oct 21, 2013 at 21:24
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
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.
This is probably too late to solve the original poster’s question but it may help someone else.
answered Dec 27, 2013 at 22:02
JamesJames
3301 silver badge12 bronze badges
This is the RegKey I used:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor]
"DisableUNCCheck"=dword:00000001
answered Oct 31, 2018 at 19:03
Editing Windows registries is not worth it and not safe, use Map network drive
and load the network share as if it’s loaded from one of your local drives.
answered Nov 8, 2019 at 0:20
DomDom
5905 silver badges26 bronze badges
3
My env windows10 2019 lts version and I add this two binray data ,fix this error
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor
DisableUNCCheck value 1
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Command Processor
DisableUNCCheck value 1
answered Aug 26, 2019 at 2:33
1
This is a very old thread, but I still use Windows 7.
There is one point that no one seems to have taken into account, which probably would help Windows 10 users also.
If Command Extensions are enabled, the PUSHD command accepts network paths in addition to the normal drive letter and path.
So the obvious — and simplest — answer might be to enable command extensions in the batch script, if you intend to use PUSHD. At the very least, this ought to reduce the problems you might have in using PUSHD wqith a network path.
answered May 22, 2020 at 11:00
Ed999Ed999
2,8312 gold badges16 silver badges19 bronze badges
I stumbled upon this question while searching for a solution to a specific problem. I needed to make a batch script that sits in a network folder (UNC path) with a Python script. The goal was to be able to double click on the batch script and have it run the Python script:
- with the network folder containing the script as the working directory,
- without modifications to the Python script (no command line parameters or hard-coded paths).
- without creating another Python file.
The pushd
and popd
solutions were unsatisfactory. They work, but if the user were to get in the habit of forcefully terminating the script while it was running, they would end up with a bunch of mapped drives in My Computer since popd
wasn’t run.
I start by using cls
to clear the UNC path error. I then assign the path containing the batch script to a variable. I slice the path to remove the trailing backslash (otherwise, Python throws a SyntaxError
). Finally, I run a couple Python commands inside the batch file that change the working directory and execute the target script:
cls
@echo off
set pyfile=myscript.py
set batchdir=%~dp0
set wdir=%batchdir:~0,-1%
python -c "import os; import runpy; os.chdir(r""%wdir%""); runpy.run_path(r""%pyfile%"")"
pause
answered Aug 13, 2022 at 2:01
StefanStefan
702 silver badges5 bronze badges
Увидеть такое сообщение можно при попытке запуска bat или cmd файла с сетевого ресурса. Всё дело в том, что CMD.EXE проверяет, используется ли имя UNC для текущего каталога и считается, что имя UNC может вызвать проблемы с дочерними процессами, запущенными с этой же консоли при выходе из консоли или остановке (об этом написано на сайте Microsoft). UNC (Universal Naming Convention) — это соглашение об именовании файлов и других ресурсов, дающее машинонезависимое определение местоположения ресурса, т.е. описание пути к файлу или папке с полным указанием имени сервера и имени сетевого ресурса.
Для того, чтобы запретить CMD.EXE проверять UNC имена и запускать скрипт без вопросов, нужно сделать следующее:
Способ 1. Запретить проверять путь UNC через редактор реестра.
Запустить regedit.exe (нажать «Пуск», в поле «Найти программы и файлы» написать «regedit.exe»).
Открыть ветку реестра: HKEY_CURRENT_USER \ Software \ Microsoft \ Command Processor
Создать параметр типа DWORD (число) с наименованием DisableUNCCheck и установить его значение равное 1.
Возможные значения этого параметра:
- 0 — выводить предупреждающее сообщение и устанавливать текущий путь равный системной папке Windows.
- 1 — не выводить предупреждающее сообщение и пытаться выставить текущий путь равный UNC пути.
Способ 2. Выполнить команду, создающую параметр DisableUNCCheck
Нажать «Пуск» -> «Выполнить» или запустить «Командную строку» и выполнить команду:
reg add «HKCU\Software\Microsoft\Command Processor» /v DisableUNCCheck /t REG_DWORD /d 1
После выполнения этой команды создастся параметр как и в способе 1-м.
Теперь можно запускать bat или cmd скрипты из сетевого пути.
Способ 3. Подключить сетевой путь как сетевой диск
Для этого можно использовать такой код bat-файла с автоматическим подбором первой свободной буквы для сетевого диска:
set netdisk= for %%x IN (D E F G H I J K L M N O P Q R S T U V W X Y Z) DO ( net use %%x: <Путь_к_сетевой_папке> /persistent:no && set netdisk=%%x if not "!netdisk!"=="" goto next ) :next %netdisk%: ... dir ... net use %netdisk%: /d
<Путь_к_сетевой_папке> нужно поменять на свой путь с указанием имени компьютера и сетевого ресурса.
После подключения сетевого диска я написал команду dir, чтобы убедиться, что путь поменялся, а вам нужно написать свои команды, которые будут выполняться для сетевого ресурса. После выполнения всех нужных действий, сетевой диск отключается командой net use %netdisk%: /d
I’m not offended, however we are volunteers and while I get that you want to run our test suite, our test suite obviously doesn’t catch this problem or it would have failed before you reported it.
A better investment of your time would be trying the thing that previously didn’t work and seeing if it works now, and then confirming it, rather than attempting to fully integrate yourself into our development workflow. And while I am fully familiar with our ‘rules’ about being kind, it also includes being aware of the demands you are placing on the time of others. We triage dozens of issues a day most days, and nobody is doing it on paid time. Every 30 minutes I spend explaining how to use pytest is 30 minutes I didn’t spend cutting a pipenv release, and therefore 30 less minutes I can spend with my partner or having leisure time.
So I’m not making accusations anymore than you reporting a bug in our software is an accusation. I also provided an example, of how we run them, in case you missed anything relevant. Beyond telling you how it works on the dozens of machines we’ve set this up on, any help is going to require us to basically google it for you, which is not a good use of our time. That’s also the reason my comment was vague, since the test failures had nothing to do with pipenv. I don’t think something is wrong with your system per se, but this stuff is kind of complex and layered so I really have no idea.
I realize that this all probably doesn’t matter to you as an end user, but that’s why I’m explaining it. I’m not out to offend you, more to push you to find help on non-pipenv errors somewhere else if you continue to have them to avoid this becoming a troubleshooting forum. Put yourself in our shoes for a second— you would want the same thing
cmd: UNC-путь
CMD.EXE по умолчанию не поддерживает UNC-пути. Если попытаться выполнить команду командного процессора, в случае, если текущий путь -UNC, то в консоль выводится информация:
«Указанный путь был использован при запуске CMD.EXE в качестве текущей папки. CMD.EXE не поддерживает пути UNC. По умолчанию выбрана системная папка Windows. Ошибка в синтаксисе команды.»
или:
«CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to Windows directory.»
Параметр «DisableUNCCheck» позволяет решить эту проблему. Значение параметра может быть одним из следующих:
0 — выводить предупреждающее сообщение и устанавливать текущий путь
равный системной папке Windows.
1 — не выводить предупреждающее сообщение и пытаться выставить текущий
путь равный UNC пути.
По умолчанию в Windows параметр равен 0.
Рекомендуемое значение 1.
Подробнее: http://www.winguides.com/registry/display.php/1247/ или в статье Microsoft — Q156276
PS: а вот так можно добавить этот ключ из командной строки или скрипта
reg add «HKCU\Software\Microsoft\Command Processor» /v DisableUNCCheck /t REG_DWORD /d 1
- Remove From My Forums
-
Question
-
I am trying to run Indexer example provided for VC#. When I am trying to run I am getting following error.
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
Answers
-
Hi,
can you check what the current directory was? The cmd.exe does not support so called UNC paths (something like
\\servername\share\directory\) — so you have to use it from a local directory (e.g. c:\temp\).So how did you start the example exactly? What is the example doing? And where do you store the solution/project?
With kind regards,
Konrad
-
Proposed as answer by
Thursday, January 26, 2012 5:42 AM
-
Marked as answer by
Lie You
Monday, January 30, 2012 3:39 AM
-
Proposed as answer by