Bei mir funktioniert nicht Lowlevelformat. Villeicht kann mir jemand helfen?
<StructLayout(LayoutKind.Sequential)> _
Public Structure FORMAT_PARAMETERS
Public MediaType As DISC_GEOMETRY.MEDIA_TYPE
Public StartCylinderNumber As ULong
Public EndCylinderNumber As ULong
Public StartHeadNumber As ULong
Public EndHeadNumber As ULong
End Structure
Declare Function DeviceIoControl Lib "kernel32" Alias "DeviceIoControl" _
( _
<[In]()> ByVal hDevice As SafeFileHandle, _
<[In]()> ByVal dwIoControlCode As IoCtlControlCode, _
<[In](), [Out]()> ByVal lpInBuffer As IntPtr, _
<[In]()> ByVal nInBufferSize As UInteger, _
<[In](), [Out]()> ByVal lpOutBuffer As IntPtr, _
<[In]()> ByVal nOutBufferSize As UInteger, _
<[In]()> ByRef lpBytesReturned As UInteger, _
<[In]()> ByVal lpOverlapped As IntPtr _
) As <MarshalAs(UnmanagedType.Bool)> Boolean
Declare Function DeviceIoControl Lib "kernel32" Alias "DeviceIoControl" _
( _
<[In]()> ByVal hDevice As SafeFileHandle, _
<[In]()> ByVal dwIoControlCode As IoCtlControlCode, _
<[In](), [Out]()> ByVal lpInBuffer As FORMAT_PARAMETERS, _
<[In]()> ByVal nInBufferSize As UInteger, _
<[In](), [Out]()> ByVal lpOutBuffer As IntPtr, _
<[In]()> ByVal nOutBufferSize As UInteger, _
<[In]()> ByRef lpBytesReturned As UInteger, _
<[In]()> ByVal lpOverlapped As IntPtr _
) As <MarshalAs(UnmanagedType.Bool)> Boolean
Public Shared Function LowLevelFormat(ByVal hDisk As SafeFileHandle, ByVal _
lpGeometry As DISK_GEOMETRY) As Boolean
Dim FormatParameters As FORMAT_PARAMETERS
Dim ReturnedByteCount As Long
Dim IOCTL_DISK_FORMAT_TRACKS As Integer = &H7C018
Dim FSCTL_LOCK_VOLUME As UInt32 = &H90018
Dim FSCTL_UNLOCK_VOLUME As UInt32 = &H9001C
FormatParameters.MediaType = lpGeometry.MediaType
FormatParameters.StartCylinderNumber = 0
FormatParameters.StartHeadNumber = 0
FormatParameters.EndCylinderNumber = lpGeometry.Cylinders.QuadPart _
- 1
FormatParameters.EndHeadNumber = lpGeometry.TracksPerCylinder - 1
Dim ptrSize As Integer = Marshal.SizeOf(GetType(FORMAT_PARAMETERS))
Dim outBuffer As IntPtr = Marshal.AllocHGlobal(ptrSize)
DeviceIoControl(hDisk, FSCTL_LOCK_VOLUME, IntPtr.Zero, &H0, _
IntPtr.Zero, &H0, ReturnedByteCount, IntPtr.Zero)
DeviceIoControl(hDisk, IOCTL_DISK_FORMAT_TRACKS, FormatParameters, _
Marshal.SizeOf(FormatParameters), outBuffer, ptrSize, _
ReturnedByteCount, 0)
DeviceIoControl(hDisk, FSCTL_UNLOCK_VOLUME, IntPtr.Zero, &H0, _
IntPtr.Zero, &H0, ReturnedByteCount, IntPtr.Zero)
Return True
End Function |