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.
Thank you for the response but I need to handle it through registry. – cilerler – 2016-01-15T16:44:01.270
@cilerler I have updated my answer. – Ben N – 2016-01-15T17:01:00.683
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 – 2016-01-15T18:14:35.2101
@cilerler I figured it out, thanks to this MSDN article; my answer has again been updated.
– Ben N – 2016-01-15T18:26:56.733"Z:"="\\\\?\\UNC\\<host>\\<share>"
syntax didn't work. TheDOS 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 https://googleprojectzero.blogspot.com/2016/02/the-definitive-guide-on-win32-to-nt.html and http://www.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 – 2018-09-06T22:25:11.370