What is the best way to scan to find what drive mappings are set for all logged in users on all desktops in the domain? This will be used to determine what drive letters are in use in the environment.

This is in a corporate environment within an Active Directory 2003 domain. I currently use an SMS 2003 advertisement that runs "net use" and pipes to a log file. It takes a very long time to hit every desktop. Is there a better way?

4 Answers 4


The fastest way may be using WMI. If you're adept with Perl, you can even use the Win32 modules. Somewhere around here, I have a script that will give most of that information.

  • 1
    If you're going to use WMI, PowerShell works quite well with it, too.
    – Abs
    Apr 30, 2009 at 16:32

All these answers were very good clues to get me going. Thank you.

I happened across this VBScript example that does exactly what I was looking for and works nicely.

Here's the code snippet from that post:

'Define variables, constants and objects

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
  • Put the code you used the body of your answer.
    – nray
    May 16, 2009 at 16:29

There may be a better way, but the way you're doing it right now is actually very good, and though it feels slow, speed shouldn't be an issue.

Your users aren't changing their mappings daily, and even if they are you probably only care about those mappings that are relatively permanent.

Running the net use advertisement, though it takes awhile, only needs to be done a few times a month to keep on top of drive mappings.



I actually wrote a program at one point in time that would run as part of the login script and collect that information then publish it to a database with a web site. Would this be something you'd be interested in running? I could dust off the old code and hand it over if you like.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .