We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

Software to locate mapped drives on network client PCs

ghutchins
ghutchins asked
on
Medium Priority
244 Views
Last Modified: 2012-05-06
I am looking for a way to locate what drive letters certain client PCs on the domain have mapped. The below code works locally but not on remote clients.
Option Explicit
 
Dim strComputer, objWMIService, colDrives, objDrive
 
strComputer = Inputbox ("Please enter the station name")
 
If strComputer = "" then WScript.Quit
 
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

Open in new window

Comment
Watch Question

This is the solution
'Define variables, constants and objects
 
strComputer = Inputbox ("Please enter the station name")
Const HKEY_USERS = &H80000003
Set objWbem = GetObject("winmgmts:")
Set objRegistry = GetObject("winmgmts://" & strComputer & "/root/default:StdRegProv")
Set objWMIService = GetObject("winmgmts:"  & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
'Go and get the currently logged on user by checking the owner of the Explorer.exe process.  
 
Set colProc = objWmiService.ExecQuery("Select Name from Win32_Process" & " Where Name='explorer.exe' and SessionID=0")
 
If colProc.Count > 0 Then
   For Each oProcess In colProc
       oProcess.GetOwner sUser, sDomain
   Next
End If
 
'Loop through the HKEY_USERS hive until (ignoring the .DEFAULT and _CLASSES trees) until we find the tree that 
'corresponds to the currently logged on user.
lngRtn = objRegistry.EnumKey(HKEY_USERS, "", arrRegKeys)    
   
For Each strKey In arrRegKeys
   If UCase(strKey) = ".DEFAULT" Or UCase(Right(strKey, 8)) = "_CLASSES" Then
   Else
 
       Set objSID = objWbem.Get("Win32_SID.SID='" & strKey & "'")
 
'If the account name of the current sid we're checking matches the accountname we're looking for Then
'enumerate the Network subtree
       If objSID.accountname = sUser Then 
           regpath2enumerate = strkey & "\Network" 'strkey is the SID
           objRegistry.enumkey hkey_users, regpath2enumerate, arrkeynames
               
'If the array has elements, go and get the drives info from the registry
           If Not (IsEmpty(arrkeynames)) Then
               For Each subkey In arrkeynames
                   regpath = strkey & "\Network\" & subkey
                   regentry = "RemotePath"
                   objRegistry.getstringvalue hkey_users, regpath, regentry, dapath
                   wscript.echo subkey & ":" & vbTab & dapath
               Next
           End If
       End If
   End If
Next

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.