Recovering serial from hard drive by C++ without using WMI

Asked

Viewed 295 times

0

I need to get the MAC and Serial from the HD volume (in 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 be clear), and on the same button as the second function it needs to play the volume serial ("vol C:" of cmd) in another textbox. However, Getvolumeinformation() does not function on any machine I have in any version of VS (it keeps triggering error C1189 "in target Architecture") and I could not solve. :/

got that 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 were 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 don’t understand what the _T is

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

And I could handle the prompt output

system("vol C:");

to play the result in a variable without creating a file for such?

1 answer

1

Function to catch the Serial from the hard drive

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);
}
  • Getvolumeinformation ta funfando man :/ but I already got hehe snooping on microsoft’s Ocs, but thanks for the/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.