Find UNC path of a network drive?

WindowsNetworkingUncMapped Drive

Windows Problem Overview


I need to be able determine the path of the network Q drive at work for a WEBMethods project. The code that I have before is in my configuration file. I placed single character leters inside of the directories just for security reasons. I am not sure what the semi-colon is for, but I think that the double slashes are were the drive name comes to play.

Question: Is there an easy way on a Windows 7 machine to find out what the full path of the UNC is for any specific drive location?

Code:

allowedWritePaths=Q:/A/B/C/D/E/
allowedReadPaths=C:/A/B;//itpr99999/c$/A/FileName.txt
allowedDeletePaths=

Windows Solutions


Solution 1 - Windows

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.

Status       Local     Remote                    Network

-------------------------------------------------------------------------------
OK           Q:        \\server1\foo             Microsoft Windows Network
OK           X:        \\server2\bar             Microsoft Windows Network
The command completed successfully.

Note that this shows the list of mapped and connected network file shares for the user context the command is run under. If you run cmd.exe under your own user account, the results shown are the network file shares for yourself. If you run cmd.exe under another user account, such as the local Administrator, you will instead see the network file shares for that user.

Solution 2 - Windows

If you have Microsoft Office:

  1. RIGHT-drag the drive, folder or file from Windows Explorer into the body of a Word document or Outlook email
  2. Select 'Create Hyperlink Here'

The inserted text will be the full UNC of the dragged item.

Solution 3 - Windows

This question has been answered already, but since there is a more convenient way to get the UNC path and some more I recommend using Path Copy, which is free and you can practically get any path you want with one click:

https://pathcopycopy.github.io/

Here is a screenshot demonstrating how it works. The latest version has more options and definitely UNC Path too:

enter image description here

Solution 4 - Windows

The answer is a simple PowerShell one-liner:

Get-WmiObject Win32_NetworkConnection | ft "RemoteName","LocalName" -A

If you only want to pull the UNC for one particular drive, add a where statement:

Get-WmiObject Win32_NetworkConnection | where -Property 'LocalName' -eq 'Z:'  | ft "RemoteName","LocalName" -A

Solution 5 - Windows

wmic path win32_mappedlogicaldisk get deviceid, providername

Result:

DeviceID  ProviderName
I:        \\server1\Temp
J:        \\server2\Corporate
Y:        \\Server3\Dev_Repo
Z:        \\Server3\Repository

As a batch file (src):

@if [%1]==[] goto :Usage
@setlocal enabledelayedexpansion
@set _NetworkPath=
@pushd %1
@for /f "tokens=2" %%i in ('wmic path win32_mappedlogicaldisk get deviceid^, providername ^| findstr /i "%CD:~0,2%"') do @(set _NetworkPath=%%i%CD:~2%)
@echo.%_NetworkPath%
@popd
@goto :EOF
:: ---------------------------------------------------------------------
:Usage
  @echo.
  @echo. Get the full UNC path for the specified mapped drive path
  @echo.
  @echo.  %~n0 [mapped drive path]

Example:

C:\> get-unc-path.bat z:\Tools\admin

\\EnvGeoServer\Repository\Tools\admin

Batch script adapted from https://superuser.com/a/1123556/16966. Please be sure to go vote that one up too if you like this solution.

Update 2021-11-15: bug fix. Previously the batch only reported drive letter UNC root and neglected to also report the folder path.

%CD% is set from %%i through some kind of CMD magic.
%CD:~0,2% and %CD:~2% extract the drive letter and trailing path substrings respectively. e.g. :~2% does '\Tools\admin' from 'Z:\Tools\admin'.

Solution 6 - Windows

$CurrentFolder = "H:\Documents"
$Query = "Select * from Win32_NetworkConnection where LocalName = '" + $CurrentFolder.Substring( 0, 2 ) + "'"
( Get-WmiObject -Query $Query ).RemoteName

OR

$CurrentFolder = "H:\Documents"
$Tst = $CurrentFolder.Substring( 0, 2 )
( Get-WmiObject -Query "Select * from Win32_NetworkConnection where LocalName = '$Tst'" ).RemoteName

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDoug HaufView Question on Stackoverflow
Solution 1 - WindowsLachlan DowdingView Answer on Stackoverflow
Solution 2 - WindowsdlauzonView Answer on Stackoverflow
Solution 3 - WindowsIboView Answer on Stackoverflow
Solution 4 - Windowss31064View Answer on Stackoverflow
Solution 5 - Windowsmatt wilkieView Answer on Stackoverflow
Solution 6 - WindowsdieseyerView Answer on Stackoverflow