none
Volumes GUID lifetime

    Question

  • Hello everyone.

    I need to be able to programatically and constantly identify every storage volume on a computer (whether they are on hard drives, network drives, external drives, usb keys, cd-roms, etc) by GUIDs or any other unique identifier. The GUID must survive to reboots and devices being temporarily unplugged. I am aware this won't be always possible but I would like this GUID to be as reliable as possible.


    Now, Windows provides a GUID for every volume. However, as far as I understand, they can change through time, for example when some usb devices are unplugged, then plugged on another port. I would like to get some clarifications on how Windows generates those GUID and what are the limits from my perspective. My plan is to write custom GUID in hidden files on those storage devices when I cannot rely on Windows' GUID.

    * Hard drives's guid are randomly generated when formatting, then stored on the MBR, so they will always remain constant? So I can rely on Windows' guid for *all* hard drives? Or does it depends on the file system? What about drives formatted with older versions of Windows (down to Win2k)? Any problem with network drives?

    * For USB devices, the GUID may be constant for some devices and not for some others (depending on whether they do have a correctly unique serial number or not)? So I cannot rely on Windows' GUID.

    * For CD-Roms and DVD-Roms, Windows infere a GUID according to the data written to the disk? So I can rely on Windows' guid? But what about rewritable CD and DVD?

    Any help, even partial informations, would be greatly appreciated.

    Regards.



    • Edited by Raphaël P Friday, April 27, 2012 5:58 AM
    Friday, April 27, 2012 5:53 AM

Answers

  • From what I remember, there isn't even a guarantee that a volume will have the same unique volume name on different systems or different instances of Windows on the same system.

    Anyway, Windows will keep in the registry and store the volume information of a device if it is able to recognise it via some hardware serial information. So Hard disks are fine. USB devices though depend on the manufacturer, some provide a hardware serial others don't. For CD/DVD drives, the unique name refers to the drive itself not the media. So the unique name will always be the same regardless of media put in it.

    -Addendum-

    I wrote a little application that listed all the volumes and run it in both copies of Windows on this system. Here are the results.

    Volume Name: \\?\Volume{f7f5cf09-63d9-11e1-919e-806e6f6e6963}\
    Volume Name: \\?\Volume{f7f5cf07-63d9-11e1-919e-806e6f6e6963}\
    Volume Name: \\?\Volume{f7f5cf0b-63d9-11e1-919e-806e6f6e6963}\
    Volume Name: \\?\Volume{2ccd6aa0-8485-11e1-b5fe-001fd0add883}\
    Volume Name: \\?\Volume{f7f5cf0a-63d9-11e1-919e-806e6f6e6963}\
    Volume Name: \\?\Volume{f7f5cf08-63d9-11e1-919e-806e6f6e6963}\
    Volume Name: \\?\Volume{f7f5cf0c-63d9-11e1-919e-806e6f6e6963}\
    Volume Name: \\?\Volume{f7f5cf0f-63d9-11e1-919e-806e6f6e6963}\
    Volume Name: \\?\Volume{3071d7c7-6469-11e1-bcc2-001fd0add883}\
    Volume Name: \\?\Volume{5a093440-65ee-11e1-8dae-806e6f6e6963}\

    and

    Volume Name: \\?\Volume{8170d941-9077-19e1-aec2-806e6f6e6963}\
    Volume Name: \\?\Volume{8170d945-9077-19e1-aec2-806e6f6e6963}\
    Volume Name: \\?\Volume{8170d943-9077-19e1-aec2-806e6f6e6963}\
    Volume Name: \\?\Volume{8170d957-9077-19e1-aec2-806e6f6e6963}\
    Volume Name: \\?\Volume{8170d942-9077-19e1-aec2-806e6f6e6963}\
    Volume Name: \\?\Volume{8170d946-9077-19e1-aec2-806e6f6e6963}\
    Volume Name: \\?\Volume{8170d944-9077-19e1-aec2-806e6f6e6963}\
    Volume Name: \\?\Volume{d9b257fc-684e-4dcb-ab79-03cfa2f6b750}\
    Volume Name: \\?\Volume{8170d935-9077-19e1-aec2-806e6f6e6963}\

    Very different aren't they. You will notice that there are two more volumes in the first block, but this is due to virtual drives in one of the environments. The almost sequential GUIDs are my hard disks and DVD drive. As you can see, they do not keep their unique names over installs of Windows.


    This is a signature

    Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    Do you want Visual Studio 11 Express to be freely installable on Windows 7 and able to write regular C++ applications? Please vote for this.



    • Edited by Crescens2k Friday, April 27, 2012 1:57 PM
    • Marked as answer by Raphaël P Friday, April 27, 2012 9:12 PM
    Friday, April 27, 2012 1:21 PM

All replies

  • From what I remember, there isn't even a guarantee that a volume will have the same unique volume name on different systems or different instances of Windows on the same system.

    Anyway, Windows will keep in the registry and store the volume information of a device if it is able to recognise it via some hardware serial information. So Hard disks are fine. USB devices though depend on the manufacturer, some provide a hardware serial others don't. For CD/DVD drives, the unique name refers to the drive itself not the media. So the unique name will always be the same regardless of media put in it.

    -Addendum-

    I wrote a little application that listed all the volumes and run it in both copies of Windows on this system. Here are the results.

    Volume Name: \\?\Volume{f7f5cf09-63d9-11e1-919e-806e6f6e6963}\
    Volume Name: \\?\Volume{f7f5cf07-63d9-11e1-919e-806e6f6e6963}\
    Volume Name: \\?\Volume{f7f5cf0b-63d9-11e1-919e-806e6f6e6963}\
    Volume Name: \\?\Volume{2ccd6aa0-8485-11e1-b5fe-001fd0add883}\
    Volume Name: \\?\Volume{f7f5cf0a-63d9-11e1-919e-806e6f6e6963}\
    Volume Name: \\?\Volume{f7f5cf08-63d9-11e1-919e-806e6f6e6963}\
    Volume Name: \\?\Volume{f7f5cf0c-63d9-11e1-919e-806e6f6e6963}\
    Volume Name: \\?\Volume{f7f5cf0f-63d9-11e1-919e-806e6f6e6963}\
    Volume Name: \\?\Volume{3071d7c7-6469-11e1-bcc2-001fd0add883}\
    Volume Name: \\?\Volume{5a093440-65ee-11e1-8dae-806e6f6e6963}\

    and

    Volume Name: \\?\Volume{8170d941-9077-19e1-aec2-806e6f6e6963}\
    Volume Name: \\?\Volume{8170d945-9077-19e1-aec2-806e6f6e6963}\
    Volume Name: \\?\Volume{8170d943-9077-19e1-aec2-806e6f6e6963}\
    Volume Name: \\?\Volume{8170d957-9077-19e1-aec2-806e6f6e6963}\
    Volume Name: \\?\Volume{8170d942-9077-19e1-aec2-806e6f6e6963}\
    Volume Name: \\?\Volume{8170d946-9077-19e1-aec2-806e6f6e6963}\
    Volume Name: \\?\Volume{8170d944-9077-19e1-aec2-806e6f6e6963}\
    Volume Name: \\?\Volume{d9b257fc-684e-4dcb-ab79-03cfa2f6b750}\
    Volume Name: \\?\Volume{8170d935-9077-19e1-aec2-806e6f6e6963}\

    Very different aren't they. You will notice that there are two more volumes in the first block, but this is due to virtual drives in one of the environments. The almost sequential GUIDs are my hard disks and DVD drive. As you can see, they do not keep their unique names over installs of Windows.


    This is a signature

    Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    Do you want Visual Studio 11 Express to be freely installable on Windows 7 and able to write regular C++ applications? Please vote for this.



    • Edited by Crescens2k Friday, April 27, 2012 1:57 PM
    • Marked as answer by Raphaël P Friday, April 27, 2012 9:12 PM
    Friday, April 27, 2012 1:21 PM
  • Thank you very much, Crescent. Not only you made me realize that I was wrong regarding dvd and cd, but you also bring my attention to the fact that GUID are OS copy-specific (quite logical since some of the GUID's bytes depends on the machine but I thought those were the ones from the original copy), something that may matter in the future since I was more or less thinking about sending those GUID on an intranet rather than transmitting straight UNC paths.


    • Edited by Raphaël P Friday, April 27, 2012 9:18 PM
    Friday, April 27, 2012 9:11 PM