Can I create a shortcut which points to a specific drive regardless of its drive letter?

I noticed that I cannot use \\?\Volume{f993747a-5d7a-4de1-a97a-c20c1af1ba02}\path\to\target or \Device\HarddiskVolume5\path\to\target as shortcut targets—it won't work. It only works when I use drive letters in absolute paths. I don't want to use drive letters or relative paths.

Can I specify a target for a shortcut which won't break when drive letters change? Alternatively, can I create an NTFS reparse point (such as a junction point) to do this?


Solution 1:

Can I create a shortcut which points to a specific drive regardless of its drive letter?

I don't want to use drive letters or relative paths

The type of targets you wish to use (\?\Volume{f993747a-5d7a-4de1-a97a-c20c1af1ba02}\path\to\target or \Device\HarddiskVolume5\path\to\target) are not valid targets for a shortcut.

All of the valid targets for shortcuts must use one of the types specifed below.


Shortcut preference items allow you to configure a shortcut to a file system object (such as a file, folder, drive, share, or computer), a shell object (such as a printer, desktop item, or control panel item), or a URL (such as a Web page or an FTP site).

Source Configure a Shortcut Item


Alternatively, can I create an NTFS reparse point (such as a junction point) to do this?

You can use mklink to create a symbolic link of the form \\?\Volume{f993747a-5d7a-4de1-a97a-c20c1af1ba02}\path\to\target.txt

c:
md \test
cd \test
mklink testlink \\?\Volume{d1a54614-9369-11e4-b7ab-ccaf78b24c0a}\test\test.txt

Now the directory test contains a symbolic link (which in my case points to a file f:\test\test.txt on an external drive).

C:\test>dir
 Volume in drive C has no label.
 Volume Serial Number is C8D0-DF1E

 Directory of C:\test

29/03/2015  23:24    <DIR>          .
29/03/2015  23:24    <DIR>          ..
29/03/2015  23:17    <SYMLINK>      testlink [\\?\Volume{d1a54614-9369-11e4-b7ab-ccaf78b24c0a}\test\test.txt]
               1 File(s)              0 bytes
               2 Dir(s)  248,410,976,256 bytes free

...

C:\test>type testlink
this file is test.txt
C:\test>

...

C:\test>type f:\test\test.txt
this file is test.txt
C:\test>

Note

  • This only works if you try to dereference the link from the command prompt, but not if you try to access it from the explorer interface.

Further Reading

  • An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
  • mklink - Create a symbolic link to a directory or a file, or create a hard file link or directory junction.