Copy UNC network path (not drive letter) for paths on mapped drives from Windows Explorer

89

42

I frequently want to share Windows network paths to files with other folks on my team via email or chat. We have a lot of mapped drives here, both ones we set up ourselves and ones set up by our IT overlords. What I'd like to be able to do is to copy the full real path (not the drive letter) from Windows Explorer to send to folks.

Example: I have a file in my "Q:" drive, \\cartman\users\emueller, and I want to send a link to the file foo.doc therein to coworkers. When I copy the file path (shift+right click, "copy as path") it gets the file name "Q:\foo.doc" in the clipboard. This is unhelpful to others, who would need to see \\cartman\users\emueller\foo.doc to be able to consume the link.

In Explorer it clearly knows the full path - in the address bar I see "Computer -> emueller (\\cartman\users) (Q:) ->". Is there a way to say "hey man copy that path as text with the \\cartman\users\emueller not the Q: in it?"

I know I could just set up mapped network locations instead of the mapped drives for the ones that I set up personally and avoid this problem, but most of the mapped drives like the "users" share come from our corporate IT policy and can't be overridden. I could just make a separate network location and then ignore my Q: drive but that's inconvenient (and they do it so they can move accounts across servers). Sure my emailed path might eventually break because I'm losing the drive letter indirection but that's OK with me.

Ernest Mueller

Posted 2011-02-11T15:29:57.783

Reputation: 992

1

If you're running in a locked down corporate environment where you cannot install any third party applications and/or access the registry, then this solution will work ... http://superuser.com/a/704374/46099

– Richard – 2014-02-11T11:52:07.257

Answers

47

I had exactly the same problem -- not everyone had the same mapped drives as me, or mapped to the same letters.

After much searching I found a context menu extension named Path Copy Copy on GitHub (https://pathcopycopy.github.io/) which is an extended version of a similar, older extension (called Pathcopy) has quite a few options for copying paths as text, including one for UNC paths -- example of the options available are shown below:

Path Copy Context Menu example

You can also choose to show only one or two lines on the base context menu, for example you can have two lines, Copy Long Path, and Copy Long UNC Path. It's great for emailing users in your company who have access to a network path, and if they have the same network mapping as you, you can choose the former, otherwise you can use the latter.

Update: As of version 12.0, a new "portable" installer is available on the above site, which installs only for the current user into the AppData\Local folder. I've not tried this, but it could be solution for those who are prohibited from installing normally.

i_saw_drones

Posted 2011-02-11T15:29:57.783

Reputation: 610

4

A bit messy, I much prefer net use as suggested by Jimbo.

– Jonas Byström – 2013-10-16T12:39:05.090

49

Maybe a long way around but open a cmd window. Then do net use > filename

Then open the filename and you can get the path:
Ex:

C:\Users\me\net use > drives.txt

Opening drives.txt

New connections will be remembered.
Status       Local     Remote                    Network
-------------------------------------------------------------------------------
             H:        \\server\c\proj\net       Microsoft Windows Network

Can copy \\server\c\prog\net from the file for your use.

Hope this helps.

Jimbo

Posted 2011-02-11T15:29:57.783

Reputation: 491

2net use > filename confused me.. and i used my actual pdf filename in that spot thus clobbered my original pdf file. yes i know it is my bad. so take care. just use net use and copy from terminal window. and if you need it really inside a file.. then you know what to do.. `> uncpathnamefile.txt' – ihightower – 2019-02-07T04:19:17.803

10simple and easy. All other solutions in the topic are very bulk... – radistao – 2013-05-16T08:21:37.150

9Or, just skip the "> drives.txt" and copy the outputted path directly from the terminal window. – DarenW – 2013-09-04T16:59:31.317

1Simple & easy. Win. – CAD bloke – 2013-09-25T22:12:17.677

With msysgit/bash at your fingertips this is a whole lot easier than the other solutions. Grand! – Jonas Byström – 2013-10-16T11:53:48.633

39

UPDATE: CoolCol's approach is even easier than mine. Upvote that answer.

Here's the workaround I use when sending mapped-network paths via Outlook:

  1. In Windows Explorer, hold the shift button down, r-click on the file, and select "Copy as path".
  2. Insert a Hyperlink in the email and paste in the address field of the Hyperlink dialogue box. (Shortcut: ctrl-K ctrl-V + OK). At this point, the link will display the mapped drive letter as the root (Q:\foo.doc).
  3. Now, r-click and select "Edit Hyperlink..." you will notice that the Address field has been translated back into the full UNC path (\\cartman\users\emueller\foo.doc). With your mouse in the Address field, hit ctrl-A and ctrl-C to copy the full path to your clipboard, then move your cursor to the top field ("Text to Display:") hit ctrl-A and ctrl-V to display it correctly in your email.

kmote

Posted 2011-02-11T15:29:57.783

Reputation: 2 322

3In step 3. if you type a character and delete it, it will update the "Text to Display", which is easier than copy/paste. – 79E09796 – 2015-01-28T11:34:15.867

You do not need to type a character in the "Text to Display" and then delete it, just delete it. – Bae – 2016-03-18T04:32:21.297

1

See Coolcol's answer http://superuser.com/a/922152/190599 to speed up the copy by right click "Create Shortcut Here" option.

– Bae – 2016-03-18T04:40:01.733

Great tip, @Bae! I've updated my answer to point to CoolCool's. – kmote – 2018-10-15T17:00:09.717

This works, but quite a lot of trouble for something that should be standard feature in Windows. All the other answers involve more work or installation of extenal software (which is prohibited in most orgs) – LearnByReading – 2019-06-12T17:08:26.463

I do not see the things described. – DarenW – 2013-09-04T17:04:54.623

which part can't you see? Can you create the hyperlink? Do you know how to edit the link? – kmote – 2013-09-04T21:50:48.390

32

Geoff was basically spot on, but to take it one step further,

  1. RIGHT-DRAG the folder from Windows Explorer, into the body of your new email,
  2. then select 'Create Hyperlink Here'.

Coolcol

Posted 2011-02-11T15:29:57.783

Reputation: 321

2quickest and most out of the box-est – Alex – 2015-06-03T08:24:05.823

4Should be the best answer as the problem appears mostly in corporate environment and you can't install software there yourself. – berezovskyi – 2015-10-27T12:59:33.193

This needs to be merged in with kmote's answer http://superuser.com/a/454119/190599 as the two together are super quick

– Bae – 2016-03-18T04:39:10.377

The hero we need. Thank you! – Tung – 2019-11-13T00:06:57.423

20

I just had the need for the same thing OP is asking and after searching on Google and reading the answers, none of them provided what I think the OP and I are looking for.

The problem here is that one may map a network share to Drive Y whereas someone else in the organization may have the same network share mapped as Drive X; therefore, sending a link such as Y:\mydirectory may not work for anyone else except me.

As the OP explains, Explorer does show the actual path in the Explorer bar, but you cannot copy it (typing is tedious and prone to errors, so this is not an option) even if you choose copy as path from the context menu:

enter image description here

So the solution I came up with (by copying someone else's code) was a little C# program that you can call from a context menu in Explorer and will allow you to translate the Mapped drive letter to the actual UNC path.

Here's the code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Utils
{
    //This is the only piece of code I wrote
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            //Takes the parameter from the command line. Since this will
            //be called from the context menu, the context menu will pass it 
            //via %1 (see registry instructions below)
            if (args.Length == 1)
            {               
                Clipboard.SetText(Pathing.GetUNCPath(args[0]));
            }
            else
            {   
               //This is so you can assign a shortcut to the program and be able to
               //Call it pressing the shortcut you assign. The program will take
               //whatever string is in the Clipboard and convert it to the UNC path
               //For example, you can do "Copy as Path" and then press the shortcut you  
               //assigned to this program. You can then press ctrl-v and it will
               //contain the UNC path
                Clipboard.SetText(Pathing.GetUNCPath(Clipboard.GetText()));           
            }
        }
    }
}

And here's the Pathing class definition (I'll try to find the actual source as I can't remember where I found it):

public static class Pathing
{
    [DllImport("mpr.dll", CharSet = CharSet.Unicode, SetLastError = true)]
    public static extern int WNetGetConnection(
        [MarshalAs(UnmanagedType.LPTStr)] string localName,
        [MarshalAs(UnmanagedType.LPTStr)] StringBuilder remoteName,
        ref int length);
    /// <summary>
    /// Given a path, returns the UNC path or the original. (No exceptions
    /// are raised by this function directly). For example, "P:\2008-02-29"
    /// might return: "\\networkserver\Shares\Photos\2008-02-09"
    /// </summary>
    /// <param name="originalPath">The path to convert to a UNC Path</param>
    /// <returns>A UNC path. If a network drive letter is specified, the
    /// drive letter is converted to a UNC or network path. If the 
    /// originalPath cannot be converted, it is returned unchanged.</returns>
    public static string GetUNCPath(string originalPath)
    {
        StringBuilder sb = new StringBuilder(512);
        int size = sb.Capacity;

        // look for the {LETTER}: combination ...
        if (originalPath.Length > 2 && originalPath[1] == ':')
        {
            // don't use char.IsLetter here - as that can be misleading
            // the only valid drive letters are a-z && A-Z.
            char c = originalPath[0];
            if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
            {
                int error = WNetGetConnection(originalPath.Substring(0, 2),
                    sb, ref size);
                if (error == 0)
                {
                    DirectoryInfo dir = new DirectoryInfo(originalPath);

                    string path = Path.GetFullPath(originalPath)
                        .Substring(Path.GetPathRoot(originalPath).Length);
                    return Path.Combine(sb.ToString().TrimEnd(), path);
                }
            }
        }

        return originalPath;
    }
}

You build the program and put the executable somewhere in your PC, say for example, in c:\Utils

Now you add a context menu option in Explorer as so:

Regedit and then:

HKEY_CLASSES_ROOT\*\Directory\Shell

Right-click Shell --> New Key --> Name: "To UNC Path"
Right-click To UNC Path --> New Key --> Name: command
Right-click Default entry and select `Modify`
Value Data: c:\Utils\Utils.exe "%1"

You are done. Now you'll see this option when you right-click a directory from a mapped drive:

enter image description here

Note

I can provide the executable so you don't have to do the compilation yourself. Simply drop me a note here.

Icarus

Posted 2011-02-11T15:29:57.783

Reputation: 539

@JonasByström But the end result is as nice as it gets for the OP's question. So that "lot of work" is precisely what earns this answer the upvote, even though I will not use it personally – sehe – 2015-09-04T12:51:48.643

1Will be nice if you zipped up the executable file and put in a public space like Dropbox Public folder and provided a link here. =) – ADTC – 2013-08-28T07:34:32.630

3

A lot of work, I much prefer net use as suggested by Jimbo.

– Jonas Byström – 2013-10-16T12:39:38.390

12

Run the cmd.exe command net use:

C:\anywhere>net use
New connections will be remembered.
Status       Local     Remote                    Network
-------------------------------------------------------------------------------
OK           E:        \\XXXXX-XXX-XXX.whatever.com\d$
                                                Microsoft Windows Network
OK           G:        \\YYYYY-Y-YY01\SAN_INTERNAL\DEPARTMENT
                                                Microsoft Windows Network
OK           H:        \\ZZZZ-Z-ZZ01\Users$\myself
                                                Microsoft Windows Network
OK                     \\AAAAA-AAA-AAAA3\d$     Microsoft Windows Network

(Thanks Jimbo, your answer was good but not brief!)

Jonas Byström

Posted 2011-02-11T15:29:57.783

Reputation: 467

2I regret that I have only one upvote to give. This is indeed concise. Thanks. – user26398 – 2015-09-16T16:49:11.383

1This is an ideal approach – Ryan B. – 2017-03-08T14:21:52.903

5

Someone named Shawn Keene provided a solution to this in the Windows 7 Forum on the Microsoft website. It is in a feature called Network Place.

  1. Open Windows Explorer.

  2. Right-click on the Computer entry in the left pane and select “Add a network location”. Click next.

  3. Select the “Choose a custom network location” option (it was the only one presented to me) and click Next.

  4. Type in the UNC path desired and click Next twice. This adds an entry that shows up in left pane of Windows Explorer below the mapped drives, but it works just like a mapped drive and shows up that way in the Save dialog of applications.

  5. In Windows Explorer, navigate through that entry to the desired sub-directory and click in the blank area to the right of the bread crumbs path display in the top of the Windows Explorer screen and the UNC path appears and is highlighted.

Mark

Posted 2011-02-11T15:29:57.783

Reputation: 51

1if you're going to quote another source could you please link to that source as well? – DMA57361 – 2011-02-17T13:58:37.740

Originally from this post - the W7 source wasn't specifed there: http://www.countrykeepers.com/wp/?p=3017

– Mark – 2011-02-17T14:07:12.873

Hey, thanks for chiming in. I know about this, that's what I meant by "I could just set up mapped network locations instead of the mapped drives" in the question - it's that many of them come to me as mapped drives courtesy my IT department, and I'd like to be able to link those. But that's definitely a possible solution to some of the problem! – Ernest Mueller – 2011-02-18T14:24:12.487

P.S. I'd vote up your answer, but not enough rep, so "virtual +1!" – Ernest Mueller – 2011-02-18T14:28:56.320

4

  1. Open the Folder.
  2. RIGHT drag a file from the folder into Microsoft Word.

Geoff

Posted 2011-02-11T15:29:57.783

Reputation: 41

3

Hold Shift down and right-click on the file and select "Copy as path". Insert a Hyperlink in the email and paste in the address field of the Hyperlink dialogue box.

After you create the hyperlink in the email, you're done.

The link will show the mapped drive letter this is true. When the recipient(s) clicks on the link in the email, it will follow the UNC path whether the user is mapped or not.

I have tried this in other Office 2010 applications, Excel, Power Point, and Word.

keNscale

Posted 2011-02-11T15:29:57.783

Reputation: 31

This works, but it is the same answer as kmote's answer

– davidmneedham – 2018-04-24T19:02:45.503

2

You can also right click the directory name in the computer directory view and select rename. This will give you access to copy the path.

Craig

Posted 2011-02-11T15:29:57.783

Reputation: 29

1

  1. In the explorer window, right click the mapped drive in the file tree on the left.
  2. Select Rename.
  3. While the Text is highlighted, right_click->copy.
  4. Now the path is copied (with some extra text that is easily deleted after copied to a new location.

ThomB

Posted 2011-02-11T15:29:57.783

Reputation: 11

1Note that the true path doesn't always appear there, as evidenced by the fact that you can rename it. – Ben N – 2016-02-03T19:53:38.470

1

Save this in your sendto folder, mine is in C:\Documents and Settings\xxxxID\SendTo with a name like Copy UNC Filepath.vbs (must end .vbs) Now when you right click on a folder or file it will copy the UNC to the clipboard. Our personal folder is the F drive and so it doesn't convert either C: or F:

'send UNC filepath to clipboard when selected file is input as Send To
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate("about:blank")

myPath=Wscript.Arguments(0)
drive = Left(myPath,2)

if drive = "C:" OR drive = "\\" OR drive = "F:" then
    'leave unchanged
else
    Set oWSN = CreateObject("WScript.Network") 
    Set oDrives = oWSN.EnumNetworkDrives 
    For i = 0 to oDrives.Count - 1 Step 2 
        If oDrives.Item(i) = drive Then 
            sUNC = LCase(oDrives.Item(i+1)) 
            exit For
        end if
    Next 
    myPath=sUNC & Mid(myPath, 3)
end if

objIE.document.parentwindow.clipboardData.SetData "text",myPath
objIE.Quit

Colkerr

Posted 2011-02-11T15:29:57.783

Reputation: 11

To find the send to folder, type this into file explorer location bar: shell:sendto The script worked fine for me. source: https://www.dummies.com/computers/operating-systems/windows-7/how-to-add-locations-to-the-windows-7-send-to-menu/

– David Lotts – 2019-02-26T17:06:17.773

From Andrew Kelly: @Colkerr, I tried to use your "Copy UNC Filepath.vbs" but I get a VBScript compilation error on line 2 character 54 "Expected end of statement"

– Canadian Luke – 2013-10-29T16:11:29.920

This code doesn't work. I would look at http://superuser.com/a/704374/46099 instead if you're in a locked down corporate environment.

– Richard – 2014-04-03T14:33:44.943

0

Right-click the folder > Share > " share to yourself (means nothing) . you will get the path. / or \ . or click show all network shared.

aabbcc

Posted 2011-02-11T15:29:57.783

Reputation: 1

0

Alternative Simple Solution:

If you unmap the drive as a drive letter, then re-add it instead as a "network location" (i.e. right click "Computer" on the Explorer Window and select "Add a network location") Type in the full path for the folder. Going forward it will display the full path in the address bar. However, applications that depend upon the drive as a letter may fail.

Looking through the responses above I don't think I saw the simple solution above which I obtained from: https://answers.microsoft.com/en-us/windows/forum/windows_7-files/how-can-i-display-the-full-unc-path-of-a-sub/ebfd4253-8016-4cbd-b0d6-1bbeae9189f9

Aiju

Posted 2011-02-11T15:29:57.783

Reputation: 1

0

In corporate networks most IT Departments create shares using DFS Name Spaces, within DFS Shares you can right click on a folder and find its target.

The other method would be to see if the Share is published into Active Directory. The easiest way for other users to find shares without knowing the UNC path or File Server name / path.

If your sharing documents with large number of users, something like Microsoft SharePoint may be a better solution as offers a web interface (with WebDAV for UNC style access) and offers built in tools to alert other users to documents.

Hope This Helps.

dmd83

Posted 2011-02-11T15:29:57.783

Reputation: 39

1When I right click on my folders I don't see a "find target" option - what to you mean exactly? I mean, I can see the real path, it's not a mystery, I just want to be able to cut and past it and not type. As for Sharepoint, $50k in software isn't my ideal answer to "but can't I just cut and paste a path..." – Ernest Mueller – 2011-02-14T17:39:13.977

0

Create a DOS batch file like showmappeddrives.bat which contains:

@echo off    
net use
pause

Place the file on your desktop if you like.
Double click it and it will show all your mapped drives.

ThePrince

Posted 2011-02-11T15:29:57.783

Reputation: 1

If you added an explanation of how to use this, then your answer would be a duplicate of Jimbo’s answer from 2½ years ago. – G-Man Says 'Reinstate Monica' – 2014-10-09T23:24:42.987

-2

The SHIFT + RightClick "Copy as path" will copy the drive+filename (i.e. R:\test.doc), or if you are looking at the file via UNCpath the UNCpath+filename (i.e. "\nas\Documents\test.doc")

This is 'standard' behaviour of Windows, and therefore my favorite, above all explorer plugins which slow down systems.... ;)

Luuk

Posted 2011-02-11T15:29:57.783

Reputation: 101

1This does not help solve my problem. – Ernest Mueller – 2016-02-04T16:21:00.917