Ali Ali - 2 months ago 9x
C Question

CreateFile: direct write operation to raw disk "Access is denied" - Vista, Win7

The relevant Microsoft doc is:

Blocking Direct Write Operations to Volumes and Disks

CreateFile, remarks on Physical Disks and Volumes

The executable is written in C++ and it calls

to open an SD card that has no filesystem. The
and consecutive
calls are successful for
without Administrator privileges.

fails for
even with Administrator privileges. In the explorer, I set Run as Administrator under Properties > Compatibility > Privilege Level. I also tried to run the executable from an Administrator cmd (started with Ctrl+Shift+Enter, "Administrator:" is in the window title, properly elevated). Still, I get

Do I have to pass something else to
I have no idea what security attributes are, I just pass NULL, relevant code is here at line 92, and here at line 48.

Or is there anything else that should be set to run the process with Administrator privileges?

A related questions:

Can I get write access to raw disk sectors under Vista and Windows 7 in user mode?

Raw partition access in Windows Vista

How to obtain direct access to raw HD data in C?

Is there a clean way to obtain exclusive access to a physical partition under Windows?


It's quite rare to want only GENERIC_WRITE. You most likely want GENERIC_READ|GENERIC_WRITE.