I can overwrite the sectors of an External Hard Drive with the exception of protected files, in my case when trying to overwrite the sectors where MFT is saved.
How to pass any security attributes that will allow me to perform this task.
<pre>
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
What I have tried:
Performing this Task in Eleveated Mode. Set the offending Partition Access Rights to Full Control for everyone.