GetVolumeInformationA returns no value for local disk

86 Views Asked by At

I have following function which can be used to retrieve disk label by disk letter

#include<iostream>
#include<Windows.h>

using namespace std;

void GetVolumeLabel(char volume)
{
    char drive[4] = { ' ',':','\\'};
    drive[0] = volume;
    char VolumeName[MAX_PATH];
    if (!GetVolumeInformationA(
            (LPCSTR)drive,
            (LPSTR)VolumeName,
            sizeof(VolumeName),
            NULL,
            NULL,
            NULL,
            NULL,
            0)
        )
    {
        cout << "Error";
    }
    else
    {
        cout << VolumeName;
    }
}
int main()
{
    GetVolumeLabel('C');
    return 0;
}

But when i try to get label for disk "C", i get empty string and don`t udnerstand why. But, if for example, i use "D" (which is letter of inserted USB) instead of "C", this function successfully prints correct name. So, how i can get label for "C" or at least, how can i determine that the disk is local?

0

There are 0 best solutions below