0

For years, I have accepted that the Windows command prompt doesn't support UNC paths as the current directory. However, a few weeks ago, two of my colleagues reported that they could run batch files from a UNC directory.

I have have not been able to figure out what's special with these two machines. Can anyone explain this, and if possible, tell me how to setup my own command prompt to accept UNC paths?

To show you the difference, we have created a small batch file, saved it in "\rpfil01\Projects\test" and executed it from the same UNC path.

Batch file contents:

ver
dir randomFolder
cd randomFolder
pause

The results are attached as UNC supported.jpg and UNC not supported.png. As you can see from "UNC not supported.png", my machine simply defaults to "C:\Windows", but on my colleague's machine ("UNC supported.jpg") the UNC path is used as the current directory.

However, when a command prompt is using a UNC path as the current directory, "cd" cannot be used to go up or down in the directory tree. This can be seen from "UNC supported.jpg", where the dir command is able to list the contents of "randomFolder" but the cd command is unable to change the current directory to "randomFolder".

As you can see from the attached images, our Windows versions differ (even if both machines are up to date according to Windows Update). Can this behavior be some kind of bug in the older Windows version? If so, a very convenient bug. ;-)

5
  • 2
    There is a group policy that manages (enable or disable) this feature.
    – Ramhound
    Nov 18, 2020 at 17:59
  • Group policy? Where can I find and change this policy? Nov 18, 2020 at 21:43
  • 1
    @Ramhound: I think your are referring to Computer Configuration > Administrative Templates > Network > Network Provider > Hardened UNC Paths. This is disabled for me yet I can't use UNC in CMD.
    – harrymc
    Nov 18, 2020 at 21:53
  • 1
    @StianAndreOlsen: The Windows versions are not the same. UNC not supported - Windows version 2004. UNC supported - Windows version 1903.
    – harrymc
    Nov 18, 2020 at 22:03
  • 1
    @harrymc - I don’t have the page I brought up before but that’s a different policy.
    – Ramhound
    Nov 19, 2020 at 0:41

1 Answer 1

0

I have finally found the solution myself. It is not the different Windows 10 versions, it is a registry DWORD value called "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor\DisableUNCCheck". If this value equals 1, the command prompt accepts UNC paths as the current directory. If this value equals 0 (or not existing), UNC paths are not accepted by the command prompt.

When using a UNC path as current directory, there are limitations to the command prompt:

  • Many of the standard commands, like cd (change directory) and del (delete), doesn't work.
  • You cannot use the tab-key to automatically complete a half-written command, based on the contents of the current directory.
  • Plus probably a lot more that I haven't found yet.

However, programs started from the command prompt inherit the UNC directory as their current directory. Therefore, many batch files will work with this registry flag enabled, but not all. For those who don't work you still need to map a drive letter or use pushd and popd.

Follow-up questions:

  1. Do you recommend setting the DisableUNCCheck flag or not?
  2. What are the potential problems when disabling the UNC check? Security problems or something else?

After all, Microsoft has decided to ship Windows without this flag.

2
  • If you have additional questions, please ask them using the "Ask a question" button at the top. We're not a forum, answers aren't sorted by time and answering to an answer is not possible.
    – gronostaj
    Nov 19, 2020 at 9:22
  • Thanks for the reminder. I posted a new question: superuser.com/questions/1603362/… Nov 19, 2020 at 9:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.