简体   繁体   English

如何在远程用户会话上获取映射驱动器

[英]How to get mapped drives on remote users session

I need to get real mapped drives on remote session, I read remote registry for Path and Name but the label (drive letter) are missing in \\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\MountPoints2 我需要在远程会话上获取真实的映射驱动器,我读取了路径和名称的远程注册表,但是\\ Software \\ Microsoft \\ Windows \\ CurrentVersion \\ Explorer \\ MountPoints2中缺少标签(驱动器号)

If I read HKCU\\Network I have only the persistent drive (GPP drive with status Replace are missing). 如果我读HKCU \\ Network,我只有永久性驱动器(状态为“替换”的GPP驱动器丢失)。

how do I find the path, the name and the label ? 如何找到路径,名称和标签?

function get-Drives {
        param ( [ValidateNotNullOrEmpty()] $Computername, [ValidateNotNullOrEmpty()] $SID )
        try {
            $Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('USERS', $computerName)
            $RegKey = $Reg.OpenSubKey("$SID\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\MountPoints2")
            $lecteurs = $RegKey.GetSubKeyNames()
            $lecteurs | ?{$_ -notlike '{*}'} | %{
                $RegKey = $Reg.OpenSubKey("$SID\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\MountPoints2\\$_")
                $_LabelFromReg = $regKey.GetValue('_LabelFromReg')
                if ($_LabelFromReg) {
                    [pscustomobject]@{
                        Name = $_LabelFromReg
                        Label = ''
                        Path = $_ -replace('#','\')
                    }
                }
            }
        } catch {
        }
    }

Getting mapped drives remotely is error-prone. 远程获取映射驱动器容易出错。 It is far simpler and less trouble to get the list from the user. 从用户那里获得列表要简单得多,麻烦也更少。 Here is a short WSH JScript script you can give to users. 这是您可以提供给用户的简短WSH JScript脚本。 Users can run this to get a quick dialog box of mapped drives and locations: 用户可以运行它以获取一个映射驱动器和位置的快速对话框:

// mappedDrives.js

var wshNetwork = new ActiveXObject("WScript.Network");
var networkDrives = wshNetwork.EnumNetworkDrives();
var results = "";
for ( var i = 0; i < networkDrives.length; i += 2 ) {
  var resultLine = networkDrives.Item(i) + " -> " + networkDrives.Item(i + 1);
  if ( results != "" ) {
    results += "\r\n" + resultLine;
  }
  else {
    results = resultLine;
  }
}

var wshShell = new ActiveXObject("WScript.Shell");
if ( results != "" ) {
  wshShell.Popup(results, 0, "Mapped Drives");
}
else {
  wshShell.Popup("No mapped drives detected", 0, "Mapped Drives");
}

Edit: As pointed out by @Alban, this doesn't get the current logged in user's mapped drives, only drives mapped by the computer. 编辑:正如@Alban指出的那样,这不会获得当前登录用户的映射驱动器,而只会获取计算机映射的驱动器。 I'll leave the answer here as it might be useful for somebody that needs that in the future, but it is obviously not what the OP needed. 我将答案留在这里,因为它可能对将来需要的人有用,但显然不是OP所需要的。

Assuming your Helpdesk has access to remote WMI calls you could do this with the Win32_LogicalDisk WMI class. 假设您的服务台可以访问远程WMI调用,则可以使用Win32_LogicalDisk WMI类来实现。 Mapped drives are DriveType 4, so filter for that, and return DeviceID , ProviderName , and VolumeName . 映射的驱动器为DriveType 4,因此请对其进行过滤,然后返回DeviceIDProviderNameVolumeName Or rename them for ease of reading like: 或重命名它们以便于阅读,例如:

gwmi -class win32_logicaldisk -Computer $ComputerName | Where{$_.DriveType -eq 4} | select @{n='DriveLetter';e={$_.DeviceID}},VolumeName,@{n='NetworkPath';e={$_.ProviderName}}

Simple enough right? 很简单吧? Here's what I got running it against my local computer: 这是我在本地计算机上运行它的结果:

DriveLetter        VolumeName          NetworkPath
-----------        ----------          -----------
X:                 OSDisk              \\localhost\c$\temp

I'm fairly certain that should work against a remote computer for any currently mapped drives. 我相当确定,对于任何当前映射的驱动器,它都应在远程计算机上工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM