Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find UNC path of a network drive?

People also ask

How do I find the UNC path of a network drive?

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.

Where is the UNC path?

Answer: A UNC path, or Universal Naming Convention, is simply a shared folder on a computer. The purpose for this folder is so when you upgrade, the registers and back office computers know where the upgrade file is and can connect to it. An example of an UNC path is \\ComputerName\SharedFolder.

How do I find my UNC path IP address?

The hostname of the UNC path is the part between the first two backslashes and the backslash after that ( some-host in \\some-host\ ). The IP you're looking for in this case is 192.168. 1.42 .


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.


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.


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


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

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'.