Skip to main content

 none
GetFileAttributes returns Error: (19, 'GetFileAttributes', 'The media is write protected.') for onedrive RRS feed

  • Question

  • In below CPP code, I am calling GetFileAttributes  API to fetch file information. 

    I have created VSS snapshot via <g class="gr_ gr_9 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" data-gr-id="9" id="9">wmic</g> <g class="gr_ gr_8 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="8" id="8">shadowcopy</g> call create Volume='C:\' and passing snapshot path to API.

    It works fine when I am running it as process But fails when running it as windows service.

    It fails only for one-drive folder and works fine for rest of file/folders on the system.

    It failing after Windows10-1803 update.

    #include <windows.h>
    #include <stdio.h>
    int main(){

        char *path = "\\\\?\\GLOBALROOT\\Device\\HarddiskVolumeShadowCopy195\\Users\\Win10\\OneDrive";
        FILE *fp;
        fp=fopen("C:\\trunk\\err_19_log.txt", "w");
        int res1 = 0;
        res1 = GetFileAttributes(path);
        fprintf (fp, "\\\\?\\GLOBALROOT\\Device\\HarddiskVolumeShadowCopy4\\Users\\Win10\\OneDrive%d\n",res1);
        fprintf (fp, "%d", GetLastError());
        printf("%d %d", res1,GetLastError());
        fclose(fp);
        return 0;
    }


    Monday, June 11, 2018 9:18 AM