Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Function WriteBytes(ByVal path As String, _
- ByVal OFFSET_POS As Long, ByVal data As Byte()) As Boolean
- Dim handle As IntPtr = IntPtr.Zero
- handle = CreateFile(path, FileAccess.ReadWrite, FileShare.ReadWrite, _
- IntPtr.Zero, FileMode.Open, FileAttributes.Normal, IntPtr.Zero)
- Dim bytesWritten As UInteger
- Dim nativeOverlapped = New NativeOverlapped With {
- .OffsetLow = 0,
- .OffsetHigh = 0
- }
- Dim msg As Boolean = SetFilePointerEx(handle, OFFSET_POS, IntPtr.Zero,
- MoveMethod.FILE_CURRENT)
- Debug.WriteLine(String.Format("{0}: Setting Sector to position {1} ", _
- msg, OFFSET_POS 512))
- If Not WriteFile(handle, data, CUInt(data.Length), _
- bytesWritten, nativeOverlapped) Then
- Debug.WriteLine(String.Format("Unable to write to the volume. Error code: {0}", Marshal.GetLastWin32Error()))
- Return False
- End If
- Return True
- End Function
Add Comment
Please, Sign In to add comment