CreateFile on existing file in OneDrive For Business (OFB) failed as ERROR_ACCESS_DENIED

Copper Contributor

 

#include <iostream>
#include <Windows.h>
int main()
{
    HANDLE a = CreateFileW((LPCWSTR)u"D:\\OneDrive - 翁悸会\\test2.txt", GENERIC_ALL, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    DWORD b = GetLastError();
    std::cout << a << "\n" << b;
}

 

This code can successfully open or create a file anywhere other than my OFB - where, if the file exists, it will return an error code 5, ERROR_ACCESS_DENIED according to https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499-

This error happens in all subdirectories in the OFB. On the contrary, even my OneDrive Personal will allow this operation. And of course, I have full access to the OFB - I can normally create or open any file with Windows Explorer.

Either if the file does not exist or the file is not in the OFB, CreateFile succeeds.

Is it a windows bug, or I did something wrong?

OS: Win11 22499.1010

OFB: 21.225.1031.0005

0 Replies