About CreateFile on vista?

  • Thread starter Thread starter =?gb2312?B?wO66o7H1?=
  • Start date Start date
?

=?gb2312?B?wO66o7H1?=

My code :
hHandle = CreateFile( pSpDevIntfsDetData->DevicePath,
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
and i run this code in vista ,it return the lasterror 5. tell me no
Privileges. why i can get the Privileges to run creatfile?
 
What does pSpDevIntfsDetData->DevicePath point to?

There are two reasons this might fail. First, you could be trying to open a
file that you do not have read or write permissions to. Second, you could be
trying to open a file that already exists.

Try modifying the flags to see what happens. Change CREATE_NEW to
OPEN_EXISTING and see what happens. If that works the file exists and you
need to use OPEN_ALWAYS instead. Also, change the dwDesiredAccess to
MAXIMUM_ALLOWED and check the permissions you get back on the handle to see
what perms you have (or, easier still, just look at the permissions on the
file). You don't want to use MAXIMUM_ALLOWED in production code, but it is
useful for testing like this.
 
Back
Top