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?  
LVL 8
bsohn417Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.