0

My question is this: Given an offline disk connected to my windows machine, how can I get it's volume letter?

The scenario: I need to create a handler to a shared storage (with CreateFile function) in order to use it in the DeviceIoControl function (need to perform SCSI reservations).

The "CreateFile" function gets the physical drive name (i.e \.\PhysicalDisk1) or the volume letter of the disk (i.e \.\E:).

My problem is, that I don't want to use the physical drive name, just the disk letter. This works fine when the disk is online, but I have to support also when the disk is offline.

Is there a way to determine the letter when the device/disk is offline? I assume there is, because when I get the disk online, windows automatically gives it the right letter. So if the operation system knows what will be the letter, there must be an API or a tool that I can use too.

Thanks, Daniel.

Hasholef
  • 703
  • 3
  • 10
  • 17
  • 2
    "windows automatically gives it the right letter" - not really. It gives the device the next free drive letter. If you are used to only using one removable disk drive, then yes: it will always be the same. But if you have more than one CD Rom, for example, Hilarity Ensues if you try to update software that you installed from "the other drive" (I've had that happen). – Jongware Apr 11 '16 at 14:12
  • Try to connect a new Disk (with the iScsi Initiator). Then, go to the Disk partitions window and make the disk online. Now you can assign a Letter, say Z:. Now each time we get if offline, then online, it will be assigned to Z: – Hasholef Apr 11 '16 at 14:49
  • That information is stored inside Windows, not on the external drive. There's no way for one Windows installation to tell what drive letter another Windows installation has assigned to a specific volume. – Harry Johnston Apr 12 '16 at 02:42
  • I'm not talking about "first windows" remotely asking "another windows" about its Drive letter. The process is internal and within one machine only. – Hasholef Apr 12 '16 at 07:26

1 Answers1

0

Unfortunately, when a drive is offline the drive letter is available for use by another drive that may be inserted. So although Windows remembers what drive letter a particular drive used to have, and it attempts to re-use the same letter when it is re-inserted, if another drive was inserted that used the remembered letter then the old drive will get a different letter if it is then inserted.

But you cannot open a Physical Drive, either by name or letter, if that drive is not currently connected. You'll simply get the equivalent of "File not found".

John Burger
  • 3,662
  • 1
  • 13
  • 23