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:
- Opened device handle using h=CreateFile(name,...) with flags GENERIC_READ & WRITE, FILE_SHARE_READ & WRITE, OPEN_EXISTING.
- WriteFile(h,buffer,count,&nwritten,NULL)
It always fails after the first 32KB are successfully written, with ACCESS DENIED error.
- Tried locking with ioctl FSCTL_LOCK_VOLUME (no difference)
- Tried dismounting (ioctl FSCTL_DISMOUNT_VOLUME) (failed)
- Tried FILE_FLAG_NO_BUFFERING (no difference)
- Always Run As Administrator
- UAC is off
- ReadFile always works just fine
What am I missing?