Windows CreateFile function does not open the disk with Generic_read access mode

Source: Internet
Author: User

After two days of completion, the gas is dying! Want to read and write disk sector, I have Baidu, it is written like this:

        

HANDLE hdevice = CreateFile (TEXT ("\\\\.\\physicaldrive1",//Drive, General PHYSICALDRIVE0 is the primary disk, I do not dry, the whole dead, virtual machine and cardGeneric_reaf,//No access to the driveFile_share_read,//share mode,Null//Default security AttributesOpen_existing,//Disposition                        0,//file AttributesNULL);//Do not copy file attributes     if(Hdevice = = INVALID_HANDLE_VALUE)//cannot open the drive    {
MessageBox ("error"); return(FALSE); }
....................... CloseHandle (hdevice);

Others use the CreateFile function to open the device, get the handle returned by the disk, the handle as the parameters of the DeviceIoControl function to the disk sector bar, I can not, die or die, Win7 under. As long as I use Generic_read or generic_write, only the error will pop up. All kinds of Baidu have not found, but the other people's home partition software does run on my computer.

Finally, I finally see, the Generic_read replaced with File_read_attributes after finally can, my handle got, haha ha! Happy!

Windows CreateFile function does not open the disk with Generic_read access mode

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.