#include <SetupApi.au3>
Const $tagPARTITION_TABLE = "byte MbrData[446];byte ActiveFlags;byte StartTrack;short StartSC;byte FileSystem;byte EndTrack;short EndSC;dword LogicalStartSector;dword SectorsCount"
Local $hDisk, $pBuffer, $tBuffer, $fResult, $iDesiredAccess, $fActivate = 1
$pBuffer = _CM_Heap_Alloc(512)
$tBuffer = DllStructCreate($tagPARTITION_TABLE, $pBuffer)
$iDesiredAccess = bitOR($GENERIC_READ, $GENERIC_WRITE)
$hDisk = _CM_Create_File("\\.\H:", $iDesiredAccess, 3, 0, 3, 0)
_CM_Device_IO_Control($hDisk, 0x90018, 0, 0, 0, 0)
_CM_Read_Device($hDisk, $pBuffer, 512)
_CM_Device_IO_Control($hDisk, 0x9001C, 0, 0, 0, 0)
_CM_Close_Handle($hDisk)
If ($fActivate) Then
DllStructSetData($tBuffer, "ActiveFlags", 0x80) ; Activate the partition
Else
DllStructSetData($tBuffer, "ActiveFlags", 0x00) ; Un-activate
EndIf
$hDisk = _CM_Create_File("\\.\H:", $iDesiredAccess, 3, 0, 3, 0)
_CM_Device_IO_Control($hDisk, 0x90018, 0, 0, 0, 0)
_CM_Write_Device($hDisk, $pBuffer, 512)
_CM_Device_IO_Control($hDisk, 0x9001C, 0, 0, 0, 0)
_CM_Close_Handle($hDisk)
_CM_Assign_Var($tBuffer, 0, _CM_Heap_Free($pBuffer))
Msgbox(0, "", "Done~!")