
You're using the wrong structure type with IOCTL_DISK_SET_PARTITION_INFO_EX. Please give a link if someone is aware of one. The above sample is for MBR partition style only. If we comment out the last call, the disk is being initialized as raw disk, But this won't meet our requirements.
Initialize drive with diskpart code#
&dskinfo, sizeof(dskinfo), // output bufferĪll the calls to DeviceIoControl() are getting succeeded except the last one with IOCTL_DISK_SET_PARTITION_INFO_EX code with error 1 (i.e Incorrect function). IOCTL_DISK_SET_PARTITION_INFO_EX, // operation to perform Pdg, sizeof DRIVE_LAYOUT_INFORMATION_EX, //output bufferĭskinfo.PartitionStyle = PARTITION_STYLE_MBR ĭ = 1048576 //0 ĭ = lgPartitionSize.QuadPart * 200 IOCTL_DISK_SET_DRIVE_LAYOUT_EX, // operation to perform Pdg-> = PARTITION_NTFT // PARTITION_IFS (NTFS partition or logical drive) Pdg->PartitionEntry.RewritePartition = TRUE Pdg->PartitionEntry.PartitionStyle = PARTITION_STYLE_MBR Pdg->PartitionStyle = PARTITION_STYLE_MBR SecureZeroMemory(pdg, dwDriverLayoutInfoExLen) LgPartitionSize.QuadPart = (1024 * 1024 * 1024) ĭWORD dwDriverLayoutInfoExLen = sizeof (DRIVE_LAYOUT_INFORMATION_EX) + 3 * sizeof(PARTITION_INFORMATION_EX) ĭRIVE_LAYOUT_INFORMATION_EX *pdg = (DRIVE_LAYOUT_INFORMATION_EX *)new BYTE

IOCTL_DISK_CREATE_DISK, // operation to perform GENERIC_READ | GENERIC_WRITE, // no access to the driveįILE_SHARE_READ | FILE_SHARE_WRITE, // share modeĭsk.PartitionStyle = PARTITION_STYLE_MBR //It can also be PARTITION_STYLE_GPTīResult = DeviceIoControl( hDevice, // device to be queried HDevice = CreateFile( TEXT("\\\\.\\PhysicalDrive7"),


Got the following code snippet by searching a bit //To open the drive We are using DeviceIoControl() method and IOCTL_DISK_CREATE_DISK, IOCTL_DISK_SET_DRIVE_LAYOUT_EX, IOCTL_DISK_SET_PARTITION_INFO_EX codes from Disk management control codes to make the disk available for use.
Initialize drive with diskpart windows#
We are trying to initialize disk with the properties of some existing disk on Windows server 2008/2012 through a C++ program.
