Access to a disk drive using volume ID instead of a drive letter in Windows

97,141

Solution 1

You can use mountvol in the command prompt to get the ID of the volume you want to access.

enter image description here

This IDs can be used to open an explorer window, independent from the drive letter

enter image description here

To create a shortcut to the drive, create a new batch file with this content:

start \\?\Volume{1b3b1146-4076-11e1-84aa-806e6f6e6963}\

Solution 2

In PowerShell, use Get-Volume piped through Format-List like this:

get-volume | fl 

will give you everything you need, for instance this SYSTEM RESERVED volume on one of my machines:

ObjectId             : {1}\\ACER-M3900\root/Microsoft/Windows/Storage/Providers_v2\WSP_Volume.ObjectId="{5b16a307-de54-11e7-8aeb-806e6f6e6963}:VO:\\?\Volume{b41b0670-0000-0000-00e8-0e8004000000}\"
PassThroughClass     :
PassThroughIds       :
PassThroughNamespace :
PassThroughServer    :
UniqueId             : \\?\Volume{b41b0670-0000-0000-00e8-0e8004000000}\
AllocationUnitSize   : 4096
DedupMode            : NotAvailable
DriveLetter          :
DriveType            : Fixed
FileSystem           : NTFS
FileSystemLabel      : SYSTEM RESERVED
FileSystemType       : NTFS
HealthStatus         : Healthy
OperationalStatus    : OK
Path                 : \\?\Volume{b41b0670-0000-0000-00e8-0e8004000000}\
Size                 : 105058304
SizeRemaining        : 33992704
PSComputerName       :

Solution 3

I prefer to use absolute drive letters for flash drives. There are adequate assignments for just about anybody unless you have 20 or more flash drives.

In Windows 7 use Windows to format and assign a drive label or if the drive already has a label, use command line "Label (drive letter) to give it a label of your choice.

Then go to control panel, system and security, administrative tools, computer management, disk management to select the drive with the label you created by right clicking on the drive, select change drive letter and paths and assign the volume to a specific drive letter. It will always mount to that drive letter if it is available.

I have labeled drives that contained live data and the labeling did not affect the existing data in any way. It seems to work just like it did on floppies back in the good old days

Solution 4

Using a Label

You can access a disk drive using its Label in PS like this:

ls -l (Get-Volume | ? FileSystemLabel -eq "Barry Allen drive").Path

It's shortened, use full format in a script for better readibility - see below

Using GptType

GPT does use fixed IDs for special partitions. We can use those for writing portable scripts, to access Recovery or System volumes on any computer without assigning it a letter:

System volume:
ls -l (Get-Partition | ? GptType -eq "{c12a7328-f81f-11d2-ba4b-00a0c93ec93b}").AccessPaths[0]

Recovery volume:
ls -l (Get-Partition | ? GptType -eq "{de94bba4-06d1-4d40-a16a-bfd50179d6ac}").AccessPaths[0] -Force
cd "$((Get-Partition | ? GptType -eq "{de94bba4-06d1-4d40-a16a-bfd50179d6ac}").AccessPaths[0])Recovery"

MSR: on UEFI, there is (should be) also MSR partition, but you can't access it as it does not have a volume nor a filesystem:
error: ls -l ((Get-Partition | ? GptType -eq "{e3c9e316-0b5c-4db8-817d-f92df00215ae}").AccessPaths[0]) -Force

Caveats

  • Get-Volume will not list hidden volumes unless it's running elevated, Get-Partition will list them non-elevated, but you can't access them further unelevated anyway.
  • With Get-ChildItem (ls) Device Path must be passed using -LiteralPath argument (-l). This is not because of '?' special character. -Path just does not work with Device Path even if '?' is escaped.
  • It's not possible to CD into the root of Device Path. But it's possible to CD to its folder.

Explanation and full format of above statements

Always use full format in a script for better readibility

ls -l ((Get-Partition | ? GptType -eq "{c12a7328-f81f-11d2-ba4b-00a0c93ec93b}").AccessPaths[0])

is short for:

Get-ChildItem -LiteralPath ((Get-Partition | Where-Object { $_.GptType -eq "{c12a7328-f81f-11d2-ba4b-00a0c93ec93b}" }).AccessPaths[0])

ls is an alias of Get-ChildItem
-l is shortened -LiteralPath
? *attribute* -eq "*value*" is shortened construct of ? { $_.*attribute* -eq "*value*" }
? is an alias of Where-Object
-Force is used to see hidden files on the Recovery volume

Use of Get-Partition and Get-Volume:
Get-Partition does provide GptType parameter, but not Label, Get-Volume gives Label, but not GptType

Share:
97,141

Related videos on Youtube

TrevorJames
Author by

TrevorJames

Updated on September 18, 2022

Comments

  • TrevorJames
    TrevorJames almost 2 years

    Can I access to a disk drive using volume ID instead of a drive letter in Windows? It could be very useful for external drives.

  • TrevorJames
    TrevorJames almost 12 years
    Yes, it is what I searched for long! Now I just need to call the mountvol command to get all volume ID's. Then using path like "\\?\Volume{}" I can access to drive with needed ID (if it presents). Thank you!
  • TrevorJames
    TrevorJames almost 12 years
    Yes, this method works with Explorer and while copying files with command line. But unfortunatelly TrueCrypt does not accept such path to a keyfile =(
  • Synetech
    Synetech about 10 years
    Unfortunately it only works if you have NetBIOS and the RPC Locator running, so this won’t work if you have hardened Windows. In addition, you’ll probably need to keep several network-related services and drivers running to use it (Workstation, Computer Browser, Server, TCP/IP NetBIOS Helper, NetBT, DHCP, DNS, etc.) This is dumb since these are local volumes. :-|
  • Frank Nocke
    Frank Nocke over 8 years
    Well.. TrueCrypt does support this for reliably mounting the right drive: @"%ProgramFiles%\TrueCrypt\TrueCrypt.exe" /v \\?\Volume{4033aabd-1234-5678-a1234567890}\ /lr /c n /q
  • Harry Johnston
    Harry Johnston over 8 years
    @Synetech: I can't replicate that; the answer as posted works fine for me even with NetBIOS and the RPC Locator, and everything else network-related I could find, disabled. (Perhaps you were mistaking the kernel path for a UNC path? Or it was only a problem on an earlier version of Windows?)
  • papo
    papo over 5 years
    to see hidden/system volumes, you must run elevated, see Caveats in my answer
  • vanowm
    vanowm about 4 years
    Unfortunately this doesn't work when you type this into folder's address bar, or when selecting folder with folder select window (i.e. when moving documents folder to a different location)