4

Based on the following registry entry I would like to map ALL users to a network drive. What should be the syntax or correct location for \\<MACHINENAME>\<SHAREDFOLDER>

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices] 
"Z:"="\\??\\C:\\Documents and Settings\\All Users\\Shared Documents"

already tried followings alternatives

"Z:"="\\??\\<MACHINENAME>\\<SHAREDFOLDER>"
"Z:"="\\\\<MACHINENAME>\\<SHAREDFOLDER>"

1 Answer 1

8

Using net use

There's an easier to do this, no need to mess around with the Registry. Create a batch file that says:

net use z: \\MACHNAME\SHAREFOLDER

Place the batch file in the universal startup folder: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp. (Note that ProgramData is a hidden folder, but it's writable to Administrators.)

If you direly need to do this by adding stuff directly to the Registry, you can use the Run key. Use this .reg file to create an entry called MapDrive that invokes net use Z: \\MACHNAME\SHAREFOLDER:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
"MapDrive"="net use Z: \\\\MACHNAME\\SHAREFOLDER"

You could also create a scheduled task that uses the Users group as its user and is set to Run only when user is logged on.

With DOS Devices

To specify a UNC path in a DOS Devices entry, you need to use the special syntax \\?\UNC\. I don't know where the ?? (double question mark) convention came from, but it seems to be incorrect, since question marks are not escaped in paths or in .reg files. Therefore, to produce a network drive in this style, use this .reg file:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices]
"Z:"="\\\\?\\UNC\\MACHNAME\\SHAREFOLDER"

Note that \\\\?\\UNC\\ is literally what goes in the .reg; don't replace UNC with anything. Interestingly enough, this type of path is not valid in normal batch-style commands, but it works here and in junctions.

Also

Finally, there's a Group Policy way of mapping drives if you have a Pro/Enterprise edition of Windows.

5
  • Thank you for the response but I need to handle it through registry.
    – cilerler
    Jan 15, 2016 at 16:44
  • @cilerler I have updated my answer.
    – Ben N
    Jan 15, 2016 at 17:01
  • I really appreciate for your answer. I already now the key you provided but I would like to achieve this through "Z:"="\\??\\<MACHINENAME>\\<SHAREDFOLDER>" syntax. I couldn't find it in anywhere what ?? stands for and how to point it to UNC paths.
    – cilerler
    Jan 15, 2016 at 18:14
  • 1
    @cilerler I figured it out, thanks to this MSDN article; my answer has again been updated.
    – Ben N
    Jan 15, 2016 at 18:26
  • "Z:"="\\\\?\\UNC\\<host>\\<share>" syntax didn't work. The DOS Devices-registry-key seems to use NT Namespace paths, so I tried "Z:"="\\??\\UNC\\<host>\\<share>>". This seems to work if the share doesn't need a password (e.g. localhost\c$). See googleprojectzero.blogspot.com/2016/02/… and nynaeve.net/?p=92 about NT-Paths. (tl;dr: NT: \??\<DosDevice>\<path>\…; DosDevice: C:,X:,UNC,COM1,…; \DosDevices\…\??\…; Win32: \\?\…\??\…; \\<host>\<share>\…\??\UNC\<host>\<share>\…; <Letter>:\…\??\<Letter>:\…)
    – T S
    Sep 6, 2018 at 22:25

You must log in to answer this question.

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