129

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

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

代码:

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

6 回答 6

320

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.

于 2014-02-01T10:51:46.747 回答
27

如果您有 Microsoft Office:

  1. - 将驱动器、文件夹或文件从 Windows 资源管理器拖到 Word 文档或 Outlook 电子邮件的正文中
  2. 选择“在此处创建超链接

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

于 2019-08-15T15:25:12.987 回答
6

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

https://pathcopycopy.github.io/

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

在此处输入图像描述

于 2017-11-15T22:48:58.077 回答
5

答案很简单PowerShell

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

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

Get-WmiObject Win32_NetworkConnection | where -Property 'LocalName' -eq 'Z:'  | ft "RemoteName","LocalName" -A
于 2020-01-28T19:27:37.843 回答
3
wmic path win32_mappedlogicaldisk get deviceid, providername

结果:

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

作为批处理文件(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]

例子:

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

\\EnvGeoServer\Repository\Tools\admin

改编自https://superuser.com/a/1123556/16966的批处理脚本。如果您喜欢此解决方案,请务必也投票支持该解决方案。

2021 年 11 月 15 日更新:错误修复。以前批处理只报告驱动器号 UNC 根,而忽略了还报告文件夹路径。

%CD%%%i通过某种 CMD 魔法设置的。
%CD:~0,2%并分别%CD:~2%提取驱动器号和尾随路径子字符串。例如:~2%'Z:\Tools\admin' 中的 '\Tools\admin'。

于 2021-04-21T15:40:26.040 回答
0
$CurrentFolder = "H:\Documents"
$Query = "Select * from Win32_NetworkConnection where LocalName = '" + $CurrentFolder.Substring( 0, 2 ) + "'"
( Get-WmiObject -Query $Query ).RemoteName

或者

$CurrentFolder = "H:\Documents"
$Tst = $CurrentFolder.Substring( 0, 2 )
( Get-WmiObject -Query "Select * from Win32_NetworkConnection where LocalName = '$Tst'" ).RemoteName
于 2020-02-04T08:36:20.443 回答