zoukankan      html  css  js  c++  java
  • 取硬盘物理序列号

    void ChangeByteOrder(LPSTR lpString, int nLen)
    {
    CHAR c;
    // 63 63 72 75 6E 2E 63 6F 6D
        for(int i = 0; i < nLen; i += 2)
    {
    = lpString[i];
    lpString[i] = lpString[i+1];
    lpString[i+1= c;
    }
    }

    //获取硬盘序列号
    VOID GetDiskNum(HWND hWnd)
    {
    CHAR szDiskNum[40]={0};
    SENDCMDINPARAMS scip = { 0 };
    CHAR szBuffer[sizeof(SENDCMDOUTPARAMS) + IDENTIFY_BUFFER_SIZE] = { 0 };
    DWORD dwBytesRet = 0;
    HANDLE hDevice=INVALID_HANDLE_VALUE;

    hDevice = CreateFileW(L"\\\\.\\PhysicalDrive0",GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,0);
    if(hDevice == INVALID_HANDLE_VALUE)
    {
    return;
    }

    scip.cBufferSize = IDENTIFY_BUFFER_SIZE;
    scip.irDriveRegs.bSectorCountReg = 1;
    scip.irDriveRegs.bSectorNumberReg = 1;
    scip.irDriveRegs.bDriveHeadReg = IDE_ATAPI_IDENTIFY;
    scip.irDriveRegs.bCommandReg = IDE_ATA_IDENTIFY;

    if(DeviceIoControl(hDevice,
    DFP_RECEIVE_DRIVE_DATA,
    &scip,
    sizeof(SENDCMDINPARAMS) - 1,
    szBuffer,
    sizeof(szBuffer),
    &dwBytesRet,
    NULL))
    {
    PSENDCMDOUTPARAMS pOut = (PSENDCMDOUTPARAMS)szBuffer;
    PIDSECTOR pIdSec = (PIDSECTOR)(pOut->bBuffer);
    ChangeByteOrder(pIdSec->sSerialNumber, sizeof(pIdSec->sSerialNumber));
    strncpy(szDiskNum, pIdSec->sSerialNumber, 20);    
    }
    SetDlgItemTextA(hWnd,IDC_STATIC_DISKNUM,szDiskNum);
    return;
    }
  • 相关阅读:
    python笔记目录
    Django 的View(视图)系统
    051_Bootstrap 框架
    050_jQuery 事件
    049_jQuery 操作标签
    048_jQuery
    016-递归函数
    047_BOM_DOM
    046_JS
    045_CSS
  • 原文地址:https://www.cnblogs.com/lzjsky/p/1892699.html
Copyright © 2011-2022 走看看