Recovering the HD Serial from C ++ without using WMI

0

I need to get the MAC and Serial HD volume (in the cmd is "vol C:"), I got the MAC by the code:

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {



    UCHAR MACData[6];
    char cWork[20];
    UUID uuid;
    UuidCreateSequential(&uuid); // Cria UUID do Sistema

    for (int i = 2; i < 8; i++)
    {
        //MAC começa no 2 byte até o 7, o loop copia ele
        MACData[i - 2] = uuid.Data4[i];
    }


    printf("Endereco MAC:\n");
    for (int i = 0; i < 6; i++)
    {
        printf("%.2x ", (int) MACData[i]);
        sprintf(cWork, "%02x", MACData[i]);
        txtMAC->Text += gcnew String(cWork);
    }
    getchar();


}

It is a button event that plays the MAC in a textbox (just to make it clear), and on the same button as the second function it needs to play the volume's serial ("vol C:" from cmd) in another textbox. However, GetVolumeInformation () does not work on any machine I have in any version of VS (it throws the error C1189 "in the target architecture") and I could not resolve it. :

I got this code:

void main()
{
TCHAR szFileSys[256];
TCHAR szVolNameBuff[256];
DWORD dwSerial = 0;
DWORD dwMFL = 0;
DWORD dwSysFlags = 0;
bool bSuccess;
char fileType[255];
int bSuccessdebug = 0;
//LPCTSTR temp = _T("E:\"); For debugging only


/*if (GetVolumeInformation(NULL, szVolNameBuff, sizeof(szVolNameBuff),
    &dwSerial, &dwMFL, &dwSysFlags, szFileSys, sizeof(szFileSys)))
    cout << dwSerial;*/




TCHAR volumeName[MAX_PATH + 1] = { 0 };

    TCHAR fileSystemName[MAX_PATH + 1] = { 0 };

    DWORD serialNumber = 0;

    DWORD maxComponentLen = 0;

    DWORD fileSystemFlags = 0;

    if (GetVolumeInformation(

        (LPCWSTR)("C:\"),

        volumeName,

        ARRAYSIZE(volumeName),

        &serialNumber,

        &maxComponentLen,

        &fileSystemFlags,

        fileSystemName,

        ARRAYSIZE(fileSystemName)))

    {

            printf(("Volume Name: %s\n"), volumeName);

            printf(("Serial Number: %lu\n"), serialNumber);

            printf(("File System Name: %s\n"), fileSystemName);

            printf(("Max Component Length: %lu\n"), maxComponentLen);

    }



}// main

Originally, the printf was like this:

            _tprintf(_T("Volume Name: %s\n"), volumeName);

            _tprintf(_T("Serial Number: %lu\n"), serialNumber);

            _tprintf(_T("File System Name: %s\n"), fileSystemName);

            _tprintf(_T("Max Component Length: %lu\n"), maxComponentLen);

I still do not understand what is the one in _T

Is there any way to solve C1189, to make this code run?

And I would like to handle the prompt output

system("vol C:");

To throw the result into a variable without creating a file for it?

    
asked by anonymous 21.07.2015 / 19:54

1 answer

1

Function to get the HD Serial

std::string StringToUpper(std::string strToConvert)
{
    for (unsigned int i = 0; i < strToConvert.length(); i++)
        strToConvert[i] = toupper(strToConvert[i]);

    return strToConvert;
}

std::string GetHardDiskSerial()
{
    DWORD NumSerie;
    char NomVol[12];
    char SysFile[16];

    GetVolumeInformation("C:/", NomVol, 12, &NumSerie, NULL, NULL, SysFile, 16);

    std::ostringstream HD;
    HD << std::hex << NumSerie;
    std::string ID = HD.str();

    return StringToUpper(ID);
}
    
22.07.2015 / 00:02