Browse an UNC path using Windows CMD without mapping it to a network drive

396,430

Solution 1

If you use pushd and popd instead of cd you won't get that UNC error.

pushd <UNC path> will create a temporary virtual drive and get into it.
popd will delete the temporary drive and get you back to the path you were when you entered pushd.

Example:

C:\a\local\path> pushd \\network_host\a\network\path

U:\a\network\path> REM a temporary U: virtual drive has been created

U:\a\network\path> popd

C:\a\local\path> REM the U: drive has been deleted

C:\a\local\path>

Solution 2

I use Git Bash to do this, since I already have it installed. As an added bonus, it also has better colors, lets me use ls, rm, etc., and uses the correct slash for paths.

enter image description here

Solution 3

Kliu's "ContextConsole Shell Extension" (aka Open Command Prompt) says it, "can even open directories from network paths (UNC paths)" (from an Explorer window).

http://code.kliu.org/cmdopen/

enter image description here

Solution 4

I also hit the UNC problem with C:\> cd \\somewhere in a C program. Found this page and learnt about the net command: net use x: \\computer name\share name and used it successfully! Thanks to all who post their experiences for others to learn from. :-)

Solution 5

If you're using XP you can have a look at this site https://web.archive.org/web/20150518102450/https://support.microsoft.com/en-us/kb/156276

(In case the link breaks again: Under Software\Microsoft\Command Processor: add a DWORD value called DisableUNCCheck if it doesn’t already exist and set it to 1.)

There is a registry value that you need to add, log out, log in again ... and now your cmd.exe does support UNC-Paths. It seems to me that you still can't cd to the path, but you can use it in other commands like dir, copy ...

An alternative might be using the pushd command, that will let you switch to the share (i guess by assigning it a temporary drive letter) https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/pushd

Share:
396,430
Andreas Grech
Author by

Andreas Grech

+++++[&gt;+++++[&gt;++++&lt;-]&lt;-]&gt;&gt;+++.--..++++++. Contactable at $(echo qernfterpu#tznvy?pbz | tr ?a-z# .n-za-m@)

Updated on September 18, 2022

Comments

  • Andreas Grech
    Andreas Grech over 1 year
    C:\> cd \\somewhere
    '\\somewhere'
    CMD does not support UNC paths as current directories.
    

    What I usually do to get around this is to map that directory to a network drive and then I could easily access it from the command prompt.

    But is there an easier way on how to get around this?

    • wullxz
      wullxz almost 13 years
      which windows do you use? If it's Windows 7, you've powershell preinstalled on your system. Powershell supports unc-paths and cmd-commands (with few exceptions).
    • Supercereal
      Supercereal almost 13 years
      You can always browse to the unc path through run.
    • Andreas Grech
      Andreas Grech almost 13 years
      @wullxz: cheers, I didn't know you could browse UNC paths with PowerShell. @kyle: That's actually a valid answer according to my question :) But I want to access it from a command line environment. Will modify my question to make this more clear.
    • Rachit_Goyal
      Rachit_Goyal almost 13 years
      If your problem is that you need to work just from the command line, you can map the network drive with the 'net' command: net use x: \\computer name\share name
    • Andreas Grech
      Andreas Grech almost 13 years
      @Aleister Crowley: Yes I know, but I'm asking if there's an easier way that doesn't involve mapping a network drive.
    • Rachit_Goyal
      Rachit_Goyal almost 13 years
      @Andreas Grech: I thought that was likely the case, that's why I put it as a comment rather than an answer.
    • Kellen Stuart
      Kellen Stuart over 7 years
      Use powershell and it works
    • Cristian Ciupitu
      Cristian Ciupitu about 6 years
    • Franklin Yu
      Franklin Yu over 5 years
      @wullxz That deserves to be an answer. Look at the answers below; "ContextConsole Shell Extension" and "Git Bash" get several upvotes. I think PowerShell is better than third-party solutions.
    • wullxz
      wullxz over 5 years
      @FranklinYu added the answer
    • Steve Rindsberg
      Steve Rindsberg almost 3 years
      If you mean to browse in Windows explorer you can start an Explorer instance pointed at the desired drive with: start \\servername\sharedpath
  • afrazier
    afrazier almost 13 years
    This program is most awesome!
  • LiuYan 刘研
    LiuYan 刘研 almost 12 years
    i'm shocked by the screenshot, it exist!
  • Dov
    Dov over 11 years
    Using pushd creates a drive mapping to the network share and then changes into a path relative to the share it creates. popd disconnects the share.
  • Isaac Rabinovitch
    Isaac Rabinovitch over 11 years
    Not very useful to a command line user.
  • Andreas Grech
    Andreas Grech over 11 years
    Yes, but using net use will map that location to a network drive and that is not what I wanted.
  • Pacerier
    Pacerier over 9 years
    @AndreasGrech, Actually pushd does that too.
  • Pacerier
    Pacerier over 9 years
    The pages you linked seem like empty pages......
  • BigBlackDog
    BigBlackDog over 9 years
    The links work here. Have you tried using https?
  • Dzmitry Lahoda
    Dzmitry Lahoda almost 8 years
    This works well in Far+ConEmu, unlike pushd.
  • user121391
    user121391 almost 8 years
    You can also use backslashes if you escape them with backslashes: cd \\\\server\\share\\subdirectory
  • user121391
    user121391 almost 8 years
    Also, if you try to use tab completion with computer names, the shell might lock up for some time until the names are resolved.
  • kayleeFrye_onDeck
    kayleeFrye_onDeck about 7 years
    This didn't work for me on Windows 10. C:\WINDOWS\system32>pushd \\some\network\path ' ' CMD does not support UNC paths as current directories.
  • GreXLin85
    GreXLin85 about 7 years
    remember to open the //drive and not a mapped version. It will fail on mapped.
  • Diziet
    Diziet almost 7 years
    It's just worked for me in Windows 10, how odd. I did pushd \\ServerName\home\dir\dir2.
  • WesternGun
    WesternGun almost 7 years
    Native and elegant, just a wonder. Works for Windows 10.
  • Jay Elston
    Jay Elston over 6 years
    I agree that this is an amazing piece of software, but how can it be used to get around the fact that the CMD window app does not handler UNC?
  • Perkins
    Perkins about 6 years
    Is there any trick to make it work when the share credentials don't match the machine's user credentials?
  • Shicheng Guo
    Shicheng Guo over 5 years
    works perfect. and I need check how to put these kind of directory into perl script.
  • Jacob Krall
    Jacob Krall over 5 years
    @Perkins: I was able to use runas.exe to run PowerShell as the other user
  • Perkins
    Perkins over 5 years
    @JacobKrall That would work if another user has the proper credentials. If it's a totally different set of credentials, use cmdkey.
  • KansaiRobot
    KansaiRobot over 5 years
    it does not work for me
  • Martin
    Martin about 5 years
    @Pacerier But pushd automatically selects a drive letter and disconnects the network drive when it’s no longer needed (after popd or exit).
  • Kimmi
    Kimmi almost 5 years
    Works perfect. I was using the sshfs, if it will automatically create a virtual drive (Z, in my case). And access normally to Z like the ones did in C or D.
  • G-Man Says 'Reinstate Monica'
    G-Man Says 'Reinstate Monica' over 4 years
    The most elegant way to change directories (a read-only operation) is to modify the filesystem?  And where do you create the link?  \Temp?  You might not have write access to the current directory.  And what do you call the link?  What if there’s already a \Temp\somewhere that isn’t already a link to \\somewhere?  What if it’s a file that’s in use?  Etc…  How is this more elegant than pushd?
  • T S
    T S about 3 years
    Seems to still work under windows 10 20H2
  • jackhab
    jackhab almost 3 years
    I also noticed that if you pushd to the same location it will map a new network drive again and again and if you close the shell and open a new one calling popd will not, of course, be able to unmap them so one could end up having a bunch of unused network drives.
  • Engineer Toast
    Engineer Toast almost 3 years
    @kayleeFrye_onDeck I receive that same error once every available drive letter has been reserved. I used PUSHD on the same folder several times and filled "This PC" with letters B & D-Z. (C was my local drive but I don't know what A was. Possibly, it's a hidden partition but I couldn't find it.) The next time I tried to exact command that had just worked 15 times in a row, I got the same error you posted: ' ' CMD does not support UNC paths as current directories.
  • kayleeFrye_onDeck
    kayleeFrye_onDeck over 2 years
    @EngineerToast thanks for the heads up! Very possible that was the problem for me.