Running into a new Windows 10 error code opening a file for reading with CreateFile()
. We get error 395, but there is scant information available about what it means or how to resolve. The details of the error from the Windows 10 SDK are as follows
ERROR_CLOUD_FILE_ACCESS_DENIED
The machine in question is Windows 10 Professional. It is running OneDrive, but the file is not located under the OneDrive folder. We suspect OneDrive may be using it's Known Folder Move feature
The code used to open the file is:
HANDLE hnd = ::CreateFile(fname,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_SEQUENTIAL_SCAN,
NULL);
if (hnd == INVALID_HANDLE_VALUE) {
DWORD exitcode = ::GetLastError();
printf("%d\n", exitcode);
}
If anyone has encountered this issue, we'd appreciate any insight you can share.
After careful research, we discovered this was caused by a simple permission issue. The user process executing the CreateFile()
call did not have permissions to access the file which was being stored in the cloud. OneDrive's Known File Move
had without our realizing it caused the folder to be stored in the cloud.
Once we realized it was a cloud-permission-issue, it was a simple matter to fix the cloud permission to allow the user process to open the file.
In our particular case, we arranged to run our process as Administrator, which allowed our call to CreateFile()
to succeed. If you are trying to access a file stored in a OneDrive share that is owned by another user, then you will not be able to use this solution. You will need to ask the file owner to grant you the access you are requesting.