Search code examples
drivecreatefilewritefile

How to write to PhysicalDrive?


I am trying to write to a PhysicalDrive, e.g. "PhysicalDriveN", with no luck. The drive is a USB thumb drive (4GB).

What I tried:

  1. Opened device handle using h=CreateFile(name,...) with flags GENERIC_READ & WRITE, FILE_SHARE_READ & WRITE, OPEN_EXISTING.
  2. WriteFile(h,buffer,count,&nwritten,NULL)
    It always fails after the first 32KB are successfully written, with ACCESS DENIED error.
  3. Tried locking with ioctl FSCTL_LOCK_VOLUME (no difference)
  4. Tried dismounting (ioctl FSCTL_DISMOUNT_VOLUME) (failed)
  5. Tried FILE_FLAG_NO_BUFFERING (no difference)
  6. Always Run As Administrator
  7. UAC is off
  8. ReadFile always works just fine

What am I missing?


Solution

  • I did a System Repair from the Windows 10 install DVD and everything appears to work just fine now. Go figure.