I have a Windows XP/ Server 2003 environment here users have mapped different network drives themselves using arbitrary drive letters. Some of these users do not know how to tell the true UNC path of these drives, and I would like to be able to run a script or program to query those drives and show me the drive letters and the corresponding UNC paths. I would like to see output like "net use" in that user's context so that I can see what drives THEY have mapped. I would need to do this using my own admin account, which is where the difficulty lies. I understand this information would be stored in the HKCU registry? I would love to be able to do this in Powershell, but a vbscript or even a standalone executable would do. Thanks.
The keys you're looking for are located here:
Each mapped drive is represented by a Registry key named for the drive letter. The properties of the mapping are contained in values - the ones you are most likely to be interested in are:
The keys will only exist for Persistent connections, I don't think you can find transient mappings in the registry.
The biggest problem with this approach is that you have to either connect remotely to the users machine while they are logged in or connect and enumerate the user profiles, map those to SID's and then search in the relevant Key beneath HKEY_USERS to find the relevant copy of the users hive. That's going to be a bit of work and could be quite slow if you intend to do it a lot.
If this is a regular support issue then why not provide them with a link to a batch file that does something like:
Then you just look in the share for the Username.drives file for a precise copy of what you need. Throw that into a logon script and you have a regularly refreshed copy but obviously you don't want to do that if you really don't need the info.
Edited to add If you want to pursue this using some Powershell scripting there's a sample script on this blog post by Hugo Peeters that shows how to connect to a remote registry but you will have to figure out how to map the username to their SID so you can choose the correct key under HKEY_USERS. Each user who has a profile on the target machine has a copy of their HKCU key saved under a key named with their SID, you need to find the right one and then pull the Network key information from under that.
Assuming you had a list of all workstations in C:\Workstations.txt, you could use Powershell to query WMI on each computer and output the current mappings of the logged-on user to a text file named after the computer.
In WMI/VBScript the bit you need to list out the current user's mapped drives is:
That obviously only lists them for the current logged on user on the machine that it's run on.
We're running an exercise to discover all user's mapped drives at the moment, and are running a script like this in each user's context to get that info and dump down to a network share where we can grab the files and parse them with another script later:
This can then be put in a login script or run with a software distribution tool, like Microsoft SMS/SCCM.