Find UNC path of a network drive?

后端 未结 5 2033
盖世英雄少女心
盖世英雄少女心 2020-11-30 19:03

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 charac

相关标签:
5条回答
  • 2020-11-30 19:17

    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.

    0 讨论(0)
  • 2020-11-30 19:22

    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
    
    0 讨论(0)
  • 2020-11-30 19:33
    $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
    
    0 讨论(0)
  • 2020-11-30 19:34

    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.

    0 讨论(0)
  • 2020-11-30 19:40

    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:

    0 讨论(0)
提交回复
热议问题