I am trying to initialize and split an attached virtual hard drive through the Windows API. I have successfully used DeviceIoControl () , but whenever I use the desired drive format, Windows automatically assigns the drive letter to the partition and causes the annoying "Want to format?" dialog window.
I intend to handle the formatting and installation of this section later in the program, but I'm not sure how to stop this behavior. I tried setting RecognizedPartition to FALSE, but this does not seem to have an effect.
Relevant Code:
Layout.PartitionStyle = PARTITION_STYLE_MBR; Layout.PartitionCount = 4; Layout.Mbr.Signature = MY_DISK_MBR_SIGNATURE; Layout.PartitionEntry[0].PartitionStyle = PARTITION_STYLE_MBR; Layout.PartitionEntry[0].PartitionNumber = 1; Layout.PartitionEntry[0].StartingOffset.QuadPart = MY_DISK_OFFSET; Layout.PartitionEntry[0].PartitionLength.QuadPart = (Geom.DiskSize.QuadPart - MY_DISK_OFFSET); Layout.PartitionEntry[0].Mbr.PartitionType = PARTITION_IFS; Layout.PartitionEntry[0].Mbr.BootIndicator = FALSE; Layout.PartitionEntry[0].Mbr.RecognizedPartition = FALSE; Layout.PartitionEntry[0].Mbr.HiddenSectors = (MY_DISK_OFFSET / Geom.Geometry.BytesPerSector); for (int i = 0; i < 4; i++) { Layout.PartitionEntry[i].RewritePartition = TRUE; } if (!DeviceIoControl(hDisk, IOCTL_DISK_SET_DRIVE_LAYOUT_EX, Layout, dwLayoutSz, NULL, 0, &dwReturn, NULL)) { // Handle error } DeviceIoControl(hDisk, IOCTL_DISK_UPDATE_PROPERTIES, NULL, 0, NULL, 0, &dwReturn, NULL);
What can I do to prevent automatic drive lettering?
c ++ windows-7 winapi
Justin α
ααααα
source share