I just glued together two codes I found online, and found an interesting result. Some of my flash drives have been appearing twice on the system.
Here is what the output looks like:

Drive: C:\ Volume Name:
Drive: D:\ Volume Name:
Drive: E:\ Volume Name:
Drive: F:\ Volume Name:
Drive: G:\ Volume Name: USB20FD
Drive: H:\ Volume Name: USB20FD
Drive: I:\ Volume Name: CRUZER
Drive: J:\ Volume Name: CRUZER
Press any key to continue . . .

And here is the code that I ran:

#include <windows.h>
#include <stdio.h>
#include <stddef.h>//null defined here
#include <array>//for ARRAYSIZE() method
using namespace std;

int main(){

    DWORD dwSize = MAX_PATH;
    char szLogicalDrives[MAX_PATH] = {0};
    DWORD dwResult = GetLogicalDriveStringsA(dwSize,szLogicalDrives);

    //GetVolumeInformationA() variables
    char volumeName[255];
    char fileSystemName[255];
    DWORD serialNumber=0;
    DWORD maxComponentLen = 0;
    DWORD fileSystemFlags=0;

    if (dwResult > 0 && dwResult <= MAX_PATH)
    {
        char* szSingleDrive = szLogicalDrives;
        //Returned string "C:\\ \0 D:\\ \0 E:\\ \0 \0"
        //Hits an extra \0 at the final string, which stops the loop. 
            while(*szSingleDrive)
            {
                GetVolumeInformationA(szSingleDrive,volumeName,ARRAYSIZE(volumeName),
                    &serialNumber,
                    &maxComponentLen,
                    &fileSystemFlags,
                    fileSystemName,
                    ARRAYSIZE(fileSystemName));
                //put the code here for getting the drive name. 
                printf("Drive: %s Volume Name: %s\n", szSingleDrive, volumeName);
                //printf only prints up to the first \0 character. 

                //get the next drive
                szSingleDrive += strlen(szSingleDrive) + 1;
                //strlen() only reads up to the first \0 character
                //so szSingleDrive always points to the beginning of a string. 
            }
    }
    system("pause");
}

Another thing to note is that none of my flashdrives have that U3 launchpad software that makes the flash drive run like an autorun CD, so that shouldnt be causing the duality.

In case anyone is interested I got the two code samples here:
http://social.msdn.microsoft.com/Forums/vstudio/en-US/e80e03d8-03e3-4977-aab6-835ee7011b15/getting-drive-letter-and-label
http://msdn.microsoft.com/en-us/library/windows/desktop/aa364975%28v=vs.85%29.aspx

Sorry everybody, I think I know what is causing it, didn't reset the variables.

#include <windows.h>
#include <stdio.h>
#include <stddef.h>//null defined here
#include <array>//for ARRAYSIZE() method
#include <string.h>
using namespace std;

int main(){

    DWORD dwSize = MAX_PATH;
    char szLogicalDrives[MAX_PATH] = {0};
    DWORD dwResult = GetLogicalDriveStringsA(dwSize,szLogicalDrives);

    if (dwResult > 0 && dwResult <= MAX_PATH)
    {
        char* szSingleDrive = szLogicalDrives;
        //Returned string "C:\\ \0 D:\\ \0 E:\\ \0 \0"
        //Hits an extra \0 at the final string, which stops the loop. 
            while(*szSingleDrive)
            {
                //GetVolumeInformationA() variables
                char volumeName[255];
                memset(volumeName, '\0', 255);
                char fileSystemName[255];
                memset(fileSystemName, '\0', 255);
                DWORD serialNumber=0;
                DWORD maxComponentLen = 0;
                DWORD fileSystemFlags=0;

                GetVolumeInformationA(szSingleDrive,volumeName,ARRAYSIZE(volumeName),
                    &serialNumber,
                    &maxComponentLen,
                    &fileSystemFlags,
                    fileSystemName,
                    ARRAYSIZE(fileSystemName));
                //put the code here for getting the drive name. 
                printf("Drive: %s Volume Name: %s\n", szSingleDrive, volumeName);
                //printf only prints up to the first \0 character. 

                //get the next drive
                szSingleDrive += strlen(szSingleDrive) + 1;
                //strlen() only reads up to the first \0 character
                //so szSingleDrive always points to the beginning of a string. 
            }
    }
    system("pause");
}

Edited 3 Years Ago by overwraith

This question has already been answered. Start a new discussion instead.