• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            我生如山

            [導(dǎo)入]用DeviceIoControl獲取系統(tǒng)磁盤信息

            代碼:
            #include <iostream>
            #include <windows.h>
            using namespace std;

            int main()
            {
             SECURITY_ATTRIBUTES secStru;
             secStru.bInheritHandle=0;
             secStru.lpSecurityDescriptor=0;
             secStru.nLength=0; 
             HANDLE hDevice=CreateFile("\\\\.\\PhysicalDrive0",GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL);

             if(hDevice==INVALID_HANDLE_VALUE)
             {
              return -1;
             }

             //DWORD outBuff[1000];
             GET_LENGTH_INFORMATION infoStruct;

             memset(&infoStruct,0,sizeof(infoStruct));
             DWORD bytesReturned;
             if(DeviceIoControl(hDevice,IOCTL_DISK_GET_LENGTH_INFO,NULL,0,&infoStruct,sizeof(infoStruct),&bytesReturned,NULL)==0)
             {
              cout<<"Failed to get disk information."<<endl;
              DWORD error;
              error=GetLastError();
              HRESULT hRe=HRESULT_FROM_WIN32(error);
              char errorData[10];
              sprintf(errorData,"%x",hRe);
              cout<<"Error code:"<</*hRe*/errorData<<endl;
              CloseHandle(hDevice);
              return -1;
             }

             DISK_GEOMETRY_EX geoStruct;
             memset(&geoStruct,0,sizeof(geoStruct));
             if(DeviceIoControl(hDevice,IOCTL_DISK_GET_DRIVE_GEOMETRY_EX ,NULL,0,&geoStruct,sizeof(geoStruct),&bytesReturned,NULL)==0)
             {
              cout<<"Failed to get disk information."<<endl;
              DWORD error;
              error=GetLastError();
              HRESULT hRe=HRESULT_FROM_WIN32(error);
              char errorData[10];
              sprintf(errorData,"%x",hRe);
              cout<<"Error code:"<</*hRe*/errorData<<endl;
              CloseHandle(hDevice);
              return -1;
             }

             cout<<"The disk's size is:"<<infoStruct.Length.QuadPart/1024/1024/1024<<" G Bytes."<<endl;
             cout<<"The disk's cylinder number:"<<geoStruct.Geometry.Cylinders.QuadPart<<endl;
             cout<<"The disk's media type:"<<geoStruct.Geometry.MediaType<<endl;
             cout<<"Number of tracks per cylinder:"<<geoStruct.Geometry.TracksPerCylinder<<endl;
             cout<<"Number of sectors per track:"<<geoStruct.Geometry.SectorsPerTrack<<endl;
             cout<<"Number of bytes per sector:"<<geoStruct.Geometry.BytesPerSector<<endl;

             PDISK_PARTITION_INFO  partitionInfo=DiskGeometryGetPartition(&geoStruct);

             DRIVE_LAYOUT_INFORMATION_EX layOutInfo[20];

             memset(&layOutInfo,0,sizeof(DRIVE_LAYOUT_INFORMATION_EX)*20);

             //layOutInfo.PartitionEntry=*(new PARTITION_INFORMATION_EX[10]);

             if(DeviceIoControl(hDevice,IOCTL_DISK_GET_DRIVE_LAYOUT_EX,NULL,0,&layOutInfo,sizeof(DRIVE_LAYOUT_INFORMATION_EX)*20,&bytesReturned,NULL)==0)
             {
              cout<<"Failed to get disk information."<<endl;
              DWORD error;
              error=GetLastError();
              HRESULT hRe=HRESULT_FROM_WIN32(error);
              char errorData[10];
              sprintf(errorData,"%x",hRe);
              cout<<"Error code:"<</*hRe*/errorData<<endl;
              CloseHandle(hDevice);
              return -1;
             }

             int partitionCount=layOutInfo[0].PartitionCount;
             cout<<"Number of partitions:"<<layOutInfo[0].PartitionCount<<endl;
             cout<<"Partitions' information:"<<endl;
             for(int i=0;i<partitionCount;i++)
             {
              //PDISK_PARTITION_INFO pParInfo=partitionInfo+i*sizeof(DISK_PARTITION_INFO);
              if(layOutInfo[i].PartitionEntry[0].PartitionNumber!=0)
              {
               cout<<"Partition "<<layOutInfo[i].PartitionEntry[0].PartitionNumber<<",  partition size is "<<layOutInfo[i].PartitionEntry[0].PartitionLength.QuadPart/1024/1024/1024<<" G Bytes, partition style is "<<layOutInfo[i].PartitionEntry[0].PartitionStyle<<endl;
              }
             }

             //cout<<"The type of partition:"<<((partitionInfo.PartitionStyle==PARTITION_STYLE_MBR) ?"MBR":((partitionInfo.PartitionStyle==PARTITION_STYLE_GPT )?"GPT":((partitionInfo.PartitionStyle==PARTITION_STYLE_RAW)?"RAW":"")))<<endl;

             CloseHandle(hDevice);

             return 0;
            }



            若我 2008-09-23 13:19 發(fā)表評論

            文章來源:http://m.shnenglu.com/dingding/archive/2008/09/23/62570.html

            posted on 2008-09-23 13:19 悟山 閱讀(510) 評論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            久久国产亚洲精品麻豆| 国产精品久久久久无码av| 岛国搬运www久久| 久久久噜噜噜久久| 伊人久久精品影院| 91精品国产综合久久久久久| 国产精品对白刺激久久久| 久久夜色精品国产www| 亚洲精品美女久久777777| 一本大道久久a久久精品综合| 久久人人爽人人人人片av| 久久久久久九九99精品| 欧美伊人久久大香线蕉综合| 久久99精品久久久久久水蜜桃| 人妻精品久久久久中文字幕69| 久久免费观看视频| 波多野结衣中文字幕久久| 伊人久久精品影院| 91精品国产91热久久久久福利| 麻豆精品久久久久久久99蜜桃 | 国产精品一久久香蕉产线看| 精品无码久久久久久久动漫| 久久人人爽人人爽人人AV| 亚洲欧美一级久久精品| 99热都是精品久久久久久| 欧美一区二区三区久久综合| 老司机午夜网站国内精品久久久久久久久 | 久久精品人人做人人爽97| 色婷婷久久久SWAG精品| 日本免费久久久久久久网站| AAA级久久久精品无码片| 久久人妻AV中文字幕| 99久久香蕉国产线看观香| 久久青青草原精品国产不卡| 国产精品VIDEOSSEX久久发布| 麻豆成人久久精品二区三区免费 | 久久精品一区二区三区不卡| 国产午夜福利精品久久2021| 久久精品国产亚洲77777| 久久久噜噜噜久久熟女AA片| 久久久精品2019免费观看|