88

Is there a command that can be used from the command line to output a list of the mapped network drives on the local system and their location on the network to a text file?

This will only be used on Windows-based systems running Windows XP.

4 Answers 4

118

net use > mapped_drives.txt should dump a list of mapped drives to the text file mapped_drives.txt

alt text

Although I tested this on Windows 7, Microsoft says net use will work on Windows XP

6
  • @MaterialEdge : Welcome!
    – Sathyajith Bhat
    Apr 29, 2010 at 2:20
  • 2
    I can confirm that it works on Windows XP. Jan 8, 2014 at 8:59
  • 2
    @GeorgeLaed it will be in the same location as where you ran the command from
    – Sathyajith Bhat
    Oct 5, 2016 at 5:17
  • 1
    Note, under Windows 8 and above, this will not work in an elevated (run as administrator) command prompt because it's in a different security context. Open a "normal" command prompt to execute the command. Oct 7, 2016 at 16:23
  • 1
    "net use" works in Win10 with normal permissions (blank list if you run the command window with admin permissions). Mar 6, 2019 at 21:02
17

NET USE was only displaying the mapped drives for my current user and current connection. After some more googling, I got here:

The drive mapping info is stored in the Registry, look in HKEY_USERS\USER\Network

So I did a reg query HKEY_USERS to list the users (which were some windows codes), then I queried all of them individually, for example:

reg query HKEY_USERS\S-1-5-21-4205028929-649740040-1951280400-500\Network /s

If you query all of them, then you get all the mappings for all users.

6

Save the following as a .vbs file and run it. It'll create a MappedDrives.txt in the folder the vbs file is run from. You can replace the strComptuer with another computer's name and get the list off of a remote computer as well.

strComputer = "."

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

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutFile = objFSO.CreateTextFile(".\MappedDrives.txt")

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

For Each objDrive in colDrives
    objOutFile.WriteLine(objDrive.DeviceID & " (" & _
      objDrive.ProviderName & ")")
Next

objOutFile.Close
1
  • Woah. This is bad ass. No idea it was possible (1) to write a query for drives, and (2) to do it remotely. Awesome post.
    – kevinarpe
    Feb 26, 2013 at 9:39
3

The following cmd (run as Administrator) will show all drive maps for all users (pulling the info from the registry)

for /f "tokens=1* delims=" %i in ('reg query HKEY_USERS /f S* /k /v ^| findstr /v /c:"End of search"')do @echo. & @( reg query "%i\Volatile Environment" /s /f USERNAME /v 2>NUL & @reg query %i\Network /f RemotePath /s 2>NUL )| findstr /r /v /c:"End of search" /c:"^$" /c:"Volatile"

You must log in to answer this question.