windows 查找网络驱动器的 UNC 路径?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21482825/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 11:19:59  来源:igfitidea点击:

Find UNC path of a network drive?

windowsnetworkinguncmapped-drive

提问by Doug Hauf

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.

我需要能够确定网络 Q 驱动器在 WEBMethods 项目中工作的路径。我之前的代码在我的配置文件中。出于安全原因,我在目录中放置了单个字符。我不确定分号是做什么用的,但我认为双斜杠是驱动器名称。

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?

问题:在 Windows 7 机器上是否有一种简单的方法可以找出任何特定驱动器位置的 UNC 完整路径?

Code:

代码:

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

回答by Lachlan Dowding

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 usecommand to list your mapped drives and their UNC paths:

在 Windows 中,如果您已经映射了网络驱动器并且您不知道它们的 UNC 路径,您可以启动命令提示符(开始 → 运行 → cmd.exe)并使用该net use命令列出您映射的驱动器及其 UNC 路径:

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.exeunder your own user account, the results shown are the network file shares for yourself. If you run cmd.exeunder another user account, such as the local Administrator, you will instead see the network file shares for that user.

请注意,这显示了运行命令的用户上下文的映射和连接的网络文件共享列表。如果您cmd.exe在自己的用户帐户下运行,则显示的结果是您自己的网络文件共享。如果您cmd.exe在另一个用户帐户下运行,例如本地管理员,您将看到该用户的网络文件共享。

回答by dlauzon

If you have Microsoft Office:

如果您有 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'
  1. - 将驱动器、文件夹或文件从 Windows 资源管理器拖动到 Word 文档或 Outlook 电子邮件的正文中
  2. 选择“在此处创建超链接

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

插入的文本将是拖动项目的完整 UNC。

回答by Ibo

This question has been answered already, but since there is a more convenient wayto 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:

这个问题已经回答了,但由于有一种更方便的方法来获取 UNC 路径,我建议使用路径复制,它是免费的,您几乎可以通过单击获得任何您想要的路径:

https://pathcopycopy.github.io/

https://pathcopycopy.github.io/

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

这是一个屏幕截图,展示了它是如何工作的。最新版本有更多选项,当然还有 UNC 路径:

enter image description here

在此处输入图片说明

回答by s31064

The answer is a simple PowerShellone-liner:

答案是一个简单PowerShell的单行:

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

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

如果您只想UNC为一个特定驱动器拉取,请添加一个 where 语句:

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

回答by dieseyer

$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