user1881297
user1881297

Reputation: 147

CreateFile returns Access_Denied in Win10

CreateFile() returns ACCESS_DENIED in Windows10 when i try in my project. If i create sample application using CreateFile() it works fine. Even tried to check admin privileges before calling CreateFile(), user is in admin mode. Same code works fine in Win 7.

Below is code sample:

 WCHAR userPath[] = L"C:\\test.txt";
 HANDLE hFile = NULL;

 hFile = ::CreateFile(userPath,
 GENERIC_READ | GENERIC_WRITE,
 0,
 NULL,
 CREATE_ALWAYS,
 FILE_ATTRIBUTE_NORMAL,
 NULL);

 if(hFile == INVALID_HANDLE_VALUE)
 {
    wprintf(L"Error HANDLE = 0x%x \n",hFile);
 }
 else
 {
    wprintf(L"Suceess HANDLE = 0x%x \n",hFile);
    ::CloseHandle(hFile);
 }

Upvotes: 0

Views: 2843

Answers (2)

user1881297
user1881297

Reputation: 147

I was running my application in browser. There was issue with IE settings. When i disabled protected mode from IE->Security->Enable protected Mode, CreateFile() worked. Another solution is adding the ip to trusted site in IE.

Upvotes: 0

David Heffernan
David Heffernan

Reputation: 612794

The most obvious explanation is that your user simply does not have sufficient rights to create files at the root level of the system drive.

Since Windows 7, and possibly even Vista, the default security configuration of the system drive permits standard user to create folders at the root level, but not files. So, my hypothesis is that you are not running your process elevated as you claim, but are in fact running the process with standard user rights. In order for you to create a file at that location you will need to either:

  1. Run the process with elevated rights, or
  2. Modify the security settings of the volume.

Upvotes: 2

Related Questions