HDD serial number flipped every 2 bytes in Windows XP, Vista and 7 but not in Windows 8

后端 未结 5 1469
一生所求
一生所求 2021-02-19 05:25

I need to get HDD serial number to use it as a key for licensing a software. I used diskid32 code in this url: http://www.winsim.com/d

5条回答
  •  [愿得一人]
    2021-02-19 05:53

    Just turn off the flip using the "flip" flag of the flibAndCodeBytes function when windows 8 or greater.

    bool shoulFlipBytes = true;
    if(IsWin8OrLater()) shouldFlipBytes = false;
    
    flipAndCodeBytes(buffer,
                     descrip->SerialNumberOffset,
                     shouldFlipBytes,
                     serialNumber);
    

    You can use this to check for windows version:

    #include 
    
    bool IsWin8OrLater() {
        DWORD version = GetVersion();
        DWORD major = (DWORD) (LOBYTE(LOWORD(version)));
        DWORD minor = (DWORD) (HIBYTE(LOWORD(version)));
    
        return (major > 6) || ((major == 6) && (minor >= 2));
    }
    

    According to http://msdn.microsoft.com/en-us/library/ms724832%28VS.85%29.aspx (Thanks to ChrisV Determine if O/S is Windows 7)

提交回复
热议问题