How to get the partition information of the hard disk

zhaozj2021-02-16  86

The following code is tested on Win2K SP4, pay attention to NBuffersize, I use 11, because my hard disk is divided into three districts, this number is generally set to: (Hard disk partition * 4 - 1) I LPPartsInfo-> partitioncount returned on the system is 12, and there is no relationship.

#include #include int main (int argc, char * argv []) {HANDLE hDevice = NULL; DWORD nBytesRead = 0; DWORD nBufferSize = sizeof (DRIVE_LAYOUT_INFORMATION) sizeof (PARTITION_INFORMATION) * 11; PDRIVE_LAYOUT_INFORMATION lpPartsInfo = (PDRIVE_LAYOUT_INFORMATION) malloc (nBufferSize); if (lpPartsInfo == NULL) {return 0;} memset (lpPartsInfo, 0, nBufferSize); // // Getting a handle to 1st via CreateFile Hard Disk () function .///////////// hdevice = createfile (".//physicaldrive0", generic_read, file_share_read | file_share_write, null, open_existing , 0, null; f (hdevice == null) {RETURN 0;} DeviceioControl (HDevice, IOCTL_DISK_GET_DRIVE_LAYOT, NULL, 0, LPPARTSINFO, NBUFFERSIZE, & NBYTESREAD, NULL); CloseHandle (HDevice Free (lppartsinfo); return 0;}

转载请注明原文地址:https://www.9cbs.com/read-12180.html

New Post(0)