Software to locate mapped drives on network client PCs

Posted on 2009-02-18
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


Open in new window

Question by:ghutchins
    1 Comment

    Accepted Solution

    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
    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
           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
               End If
           End If
       End If

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    In a hurry?.. scroll down to "HERE's HOW TO DO IT" Section. Greetings All, I was going to post this as question/solution, but its seems more appropriate as an article considering its length.  I felt it important to illucidate all the details c…
    The way I use Experts Exchange to assist me in analyzing and diagnosing a problem is I first enter a Verbose Question at Experts Exchange like: Office 2007 will hang when opening and saving files I then launch WordPad (any text editor will do) an…
    This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
    Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now