Can't write to physical disk in win 7?
I wrote a disk utility that was able to erase all physical disks. it uses windows api file calling:
destFile = CreateFile("\\\\.\\PhysicalDrive1",
GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING,createflags, NULL);
and then just call WriteFile
and make sure you write multiple multiples of sectors i.e. 512 bytes.
this has worked great in the past, on XP and even Win7 RC, all you have to do is make sure you use it as an administrator.
but now I have a Win7 pro, it doesn't work anymore! the disks are still open for writing, but the call WriteFile
on the successfully opened disk now fails!
Does anyone know why this might be? could it have anything to do with opening it with generic flags? this is always what i did before and it worked. maybe something is sharing the disk now? block records? Is there a way to properly "unmount" the disk, or at least the partitions on it, so that I have exclusive access to it?
some of the other tools that used to work don't work either, but some do, such as the WD Diagnostic erase function. and after it erases the disc, my tool then works on it too! making me believe there is some sort of "unmount" process that I need to do to the drive in order to free up write permission.
Any ideas?
Update:
the error code returned from WriteFile
is '5', ERROR_ACCESS_DENIED
but again if I erase the disk first using WD Diag, I can access and write to the disk. when I initialize the disk again and give it the partition, I get back to the error ERROR_ACCESS_DENIED
.
source to share
This is almost certainly due to preventing the driver signing attack detected by modifying sectors in the page file. This will prevent writing to the area of the disk containing the partitions.
See http://msdn.microsoft.com/en-us/library/aa365747%28VS.85%29.aspx and look at the information starting with the text "If you write directly to a volume that has a mounted filesystem", basically you must lock disk volumes in order to write to your sectors.
source to share