我有一个Windows XP / Server 2003环境,用户可以使用任意的驱动器盘符映射不同的networking驱动器。 其中一些用户不知道如何分辨这些驱动器的真正UNCpath,我希望能够运行一个脚本或程序来查询这些驱动器,并显示驱动器号和相应的UNCpath。 我希望在该用户的上下文中看到像“net use”这样的输出,以便我可以看到他们映射的驱动器。 我需要使用我自己的pipe理员帐户来做到这一点,这是困难所在。 我知道这些信息会存储在HKCUregistry中? 我希望能够在Powershell中做到这一点,但是一个vbscript甚至是一个独立的可执行文件都可以。 谢谢。
您正在寻找的钥匙位于这里:
\\HKCU\Network
每个映射的驱动器由一个名为驱动器号的registry项代表。 映射的属性包含在值中 – 您最有可能感兴趣的是:
RemotePath REG_SZ UserName REG_SZ
密钥将只存在持续连接,我不认为你可以在registry中find瞬态映射。
这种方法最大的问题是你必须在login时远程连接到用户机器,或者连接并枚举用户configuration文件,将它们映射到SID,然后在HKEY_USERS下的相关密钥中查找以find相关的副本用户蜂巢。 这将是一个有点工作,可能会很慢,如果你打算做很多事情。
如果这是一个常规的支持问题,那么为什么不提供一个batch file的链接,如下所示:
Net use > \\someserver\someshare\%username%.drives
然后,您只需查看Username.drives文件的共享内容即可获得所需内容的精确副本。 把它放到一个login脚本中,你有一个定期刷新的副本,但显然你不想这样做,如果你真的不需要的信息。
编辑添加如果你想要使用一些Powershell脚本来追求这个,Hugo Peeters在这个博客文章中有一个示例脚本,它显示了如何连接到远程registry,但是你将不得不弄清楚如何将用户名映射到他们的SID,所以你可以在HKEY_USERS下select正确的密钥。 在目标计算机上拥有configuration文件的每个用户都有一个HKCU密钥的副本,并保存在以其SID命名的密钥下,您需要find正确的密钥,然后从该密钥下拉取networking密钥信息。
假设您有C:\ Workstations.txt中所有工作站的列表,可以使用Powershell在每台计算机上查询WMI,并将login用户的当前映射输出到以计算机命名的文本文件中。
# Load list into variable, which will become an array of strings $computerlist = Get-Content C:\Workstations.txt # Prompt for credentials that have rights to access WMI on the computers $cred = Get-Credential # Loop through each item in the array (each computer in the list of computers we loaded into the variable) ForEach ($computer in $computerlist) { # Query WMI on computer using credentials and output to file with width setting so we see everything Get-WmiObject Win32_NetworkConnection -computerName $computer -credential $cred | Select LocalName,RemoteName | Out-File C:\WorkstationMappings\$env:username.txt -width 120 }
在WMI / VBScript中,需要列出当前用户的映射驱动器的位是:
Set objNetwork = WScript.CreateObject("WScript.Network") Set colDrives = objNetwork.EnumNetworkDrives For i = 0 to colDrives.Count-1 Step 2 Wscript.Echo colDrives.Item(i) & vbTab & colDrives.Item (i + 1) Next
这显然只列出了它运行的机器上当前login的用户。
我们正在运行一个练习来发现所有用户的映射驱动器,并在每个用户的上下文中运行一个脚本来获取这些信息并将其转储到networking共享中,在那里我们可以抓取这些文件并用另一个脚本parsing它们后来:
scriptVersion = "1.0" Set objShell = CreateObject("WScript.shell") Set objEnv = objShell.Environment("Process") Set objFSO = CreateObject("Scripting.FileSystemObject") Set objNetwork = CreateObject("WScript.Network") strUserName = objEnv("USERNAME") strComputerName = lcase(objEnv("COMPUTERNAME")) bPath = "\\servername\sharename" ' Server and path to save files bFile = bPath & "\" & strComputerName &"-" & strUserName & "-NetDrives.txt" 'Setup output file If objFSO.FileExists(bFile) then Set objTextFile = objFSO.OpenTextFile(bFile, 8, True) ' 8 = appending Else Set objTextFile = objFSO.OpenTextFile(bFile, 2, True) ' 2 = writing End if objTextFile.WriteLine Now & " ::: Drive mappings listing v" & scriptVersion 'Loop through current network drives Set colDrives = objNetwork.EnumNetworkDrives For i = 0 to colDrives.Count-1 Step 2 objTextFile.WriteLine colDrives.Item(i) & vbTab & colDrives.Item (i + 1) Next Set objShell = Nothing Set objFSO = Nothing Set objNetwork = Nothing Wscript.Quit(ExitErrorLevel)
然后可以将其放入login脚本中,或使用Microsoft SMS / SCCM等软件分发工具运行。