• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 382
  • Last Modified:

Obtain Drive Mappings of the Currently Logged on User of a Remote Computer

What's the easiest way to obtain the drive mappings of the currently logged on user of a remote computer?  
0
bsohn417
Asked:
bsohn417
7 Solutions
 
TyBeattyCommented:
Give this a try....


strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colDrives = objWMIService.ExecQuery _
    ("Select * From Win32_LogicalDisk Where DriveType = 4")

For Each objDrive in colDrives
    Wscript.Echo "Drive letter: " & objDrive.DeviceID
    Wscript.Echo "Network path: " & objDrive.ProviderName
Next

http://www.microsoft.com/technet/scriptcenter/resources/qanda/oct05/hey1027.mspx
0
 
NJComputerNetworksCommented:
strComputer = "."   <----- here is where you put the remote computer name  "remotepc"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colDrives = objWMIService.ExecQuery _
    ("Select * From Win32_LogicalDisk Where DriveType = 4")

For Each objDrive in colDrives
    Wscript.Echo "Drive letter: " & objDrive.DeviceID
    Wscript.Echo "Network path: " & objDrive.ProviderName
Next


-----------------------


strComputer = "bobsPC"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colDrives = objWMIService.ExecQuery _
    ("Select * From Win32_LogicalDisk Where DriveType = 4")

For Each objDrive in colDrives
    Wscript.Echo "Drive letter: " & objDrive.DeviceID
    Wscript.Echo "Network path: " & objDrive.ProviderName
Next

Copy the above to notepad... paste.  Then save as

getmappings.vbs

then run...

cscript getmappings.vbs  <enter>


0
 
TyBeattyCommented:
Or you can actaully run this and it will ask you to enter the name of the PC you want to get the info for...
==============================================================================


strComputer = InputBox("Enter PC Name to Get Mappings For")

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colDrives = objWMIService.ExecQuery _
    ("Select * From Win32_LogicalDisk Where DriveType = 4")

For Each objDrive in colDrives
    Wscript.Echo "Drive letter: " & objDrive.DeviceID
    Wscript.Echo "Network path: " & objDrive.ProviderName
Next
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
TyBeattyCommented:
Ok so I didn't care for the output of my last one so this one gives you the info and I like the output better...
==============================================================================

strComputer = InputBox("Enter PC Name to Get Mappings For")

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colDrives = objWMIService.ExecQuery _
    ("Select * From Win32_LogicalDisk Where DriveType = 4")

For Each objDrive in colDrives
    Wscript.Echo "Drive: " & objDrive.DeviceID  & "   " & objDrive.ProviderName
Next
0
 
jostranderCommented:
1 quick way:

Regedit-->File Connect Network Registry-->(enter hostname)

Navigate to (Host)\HKEY_USERS\S-1-5-21-##############...\Network
0
 
jostranderCommented:
I should note that that will only list persistent mappings.  For non-persistent drives, you'd have to look to the login script.  In the past, I've used login scripts to pipe the current mappings out to a text file on a server.

Win32_LogicalDisk will require you to run the script interactively...It would be tricky to get that working on a remote host.

Here's a method to grab all the persistent maps via registry.  Works when multiple users are logged in too (like terminal server).




'List Persistent Mappings

Const HKEY_CLASSES_ROOT 	= &H80000000
Const HKEY_CURRENT_USER 	= &H80000001
Const HKEY_LOCAL_MACHINE 	= &H80000002
Const HKEY_USERS			= &H80000003
Const HKEY_CURRENT_CONFIG 	= &H80000005

'Force CSCRIPT
Set WshShell=CreateObject("Wscript.Shell")
If instr(lcase(wscript.fullname),"wscript") then
	wshshell.run "cmd /k cscript //nologo " & chr(34) & wscript.scriptfullname & Chr(34),1,false
	wscript.quit
End If


strComputer=Inputbox("Enter the remote computer name:","Mapped Drives")
If strComputer="" then wscript.quit


'Create DICTIONARY
Set oDict = CreateObject("Scripting.Dictionary")

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")


GetProfiles

GetMappings



Sub GetProfiles
	on error resume next

   strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"

   strValueName = "ProfileImagePath"

   oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

   for each subkey in arrSubKeys
      if left(subkey,9)="S-1-5-21-" then
         oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "\" & subkey,strValueName,strValue

         user=split(strValue,"\")(ubound(split(strValue,"\")))

         oDict.add subkey,user & " (" & strValue & ")"
   
      end if
   Next

   
End Sub


Sub GetMappings
	ON ERROR RESUME NEXT


   for each key in oDict.Keys
		strDrives=""
		
		oReg.EnumKey HKEY_USERS, key & "\Network", arrLetters

		for each letter in arrLetters
			strValue=""

			oReg.GetStringValue HKEY_USERS,key & "\Network\" & letter,"RemotePath",strValue
			If strValue<>"" then strDrives=strDrives & letter & ": " & strValue
		Next
		
		If strDrives <> "" then 
			wscript.echo "-------------------------------------"
			wscript.echo oDict(key)
			wscript.echo strDrives
		End If
   next


End Sub

Open in new window

0
 
jostranderCommented:
Here's a login script that would run on the target PC.  Set it to run after all other scripts.

You'd basically end up with a folder full of text files.

computer1_userA.txt
computer2_userA.txt
computer2_userB.txt
...

I used this method once during a server migration and it worked well.
unc="\\myserver\myshare"

Set WshShell=CreateObject("Wscript.Shell")
Set WshNetwork=CreateObject("Wscript.Network")

strFilename=WshNetwork.ComputerName & "_" & WshNetwork.UserName & ".txt"

WshShell.run "cmd /c net use > """ & unc & "\" & strFilename,0,false

Open in new window

0
 
bsohn417Author Commented:
None of the suggestions worked, but appreciate the effort.  Was looking to run non-interactively.  The ones that were non-interactive did not run correctly.  
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Tackle projects and never again get stuck behind a technical roadblock.
Join Now