• <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>

            若我的小家

            -編程,讀書,感悟,旅游,設計
            posts - 21, comments - 0, trackbacks - 0, articles - 0

            用DeviceIoControl獲取系統磁盤信息

            Posted on 2008-09-23 13:19 若我 閱讀(4772) 評論(0)  編輯 收藏 引用

            代碼:
            #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;
            }

            无码人妻精品一区二区三区久久 | 东京热TOKYO综合久久精品| 模特私拍国产精品久久| 青青草原综合久久大伊人| 久久国产热精品波多野结衣AV| 99久久无码一区人妻a黑| 99久久国产热无码精品免费久久久久 | 久久久久99精品成人片三人毛片| 国内精品久久久久久久影视麻豆| 久久久久久国产a免费观看不卡 | 一本一道久久a久久精品综合 | 久久这里的只有是精品23| 日韩AV无码久久一区二区| Xx性欧美肥妇精品久久久久久| 久久91精品国产91久| 伊人色综合久久| 久久大香香蕉国产| 国产精品久久久久a影院| 精品久久一区二区三区| 香蕉久久av一区二区三区| 久久久久亚洲AV无码去区首| 狼狼综合久久久久综合网| 久久久久国产日韩精品网站| 99久久免费国产精品热| 亚洲国产精品无码久久| 亚洲人成无码网站久久99热国产| 97久久国产亚洲精品超碰热| 午夜精品久久久久久毛片| 伊人热热久久原色播放www| 久久久久久国产精品免费免费| 久久精品国内一区二区三区 | 久久久久噜噜噜亚洲熟女综合| 91久久精品91久久性色| 无码国内精品久久人妻| 色综合久久久久久久久五月| 一本久久综合亚洲鲁鲁五月天| 久久久久国产一级毛片高清板| 91超碰碰碰碰久久久久久综合| 久久精品国产一区| 国产午夜电影久久| 久久黄视频|