Windows-10 CreateFile2 error (ERROR_NOT_SUPPORTED_IN_APPCONTAINER)

末鹿安然 提交于 2019-12-12 01:35:51

问题


CreateFile2 api is returning ERROR_NOT_SUPPORTED_IN_APPCONTAINER when the file is not present/available in the path. My code is as below

   CREATEFILE2_EXTENDED_PARAMETERS ms_param = {0};
   ms_param.dwSize = sizeof(CREATEFILE2_EXTENDED_PARAMETERS);
   ms_param.dwFileAttributes = FILE_ATTRIBUTE_READONLY;
   ms_param.dwFileFlags = FILE_FLAG_NO_BUFFERING;
   ms_param.dwSecurityQosFlags = SECURITY_DELEGATION;
   ms_param.lpSecurityAttributes = NULL;
   ms_param.hTemplateFile = NULL;

   g_hfile = CreateFile2(filename, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, OPEN_EXISTING, &ms_param);
   if (g_hfile == INVALID_HANDLE_VALUE)
   {
           return GetLastError();
   }

I have already looked into this thread:CreateFile2 error in WinRT project (ERROR_NOT_SUPPORTED_IN_APPCONTAINER) , reporting similar issue. The solution suggested there doesnt work for me.

From this msdn page:CreateFile2 If the specified file or device does not exist, the function fails and the last-error code is set to ERROR_FILE_NOT_FOUND (2).But I am getting ERROR_NOT_SUPPORTED_IN_APPCONTAINER error


回答1:


@Hans Passant's, comment helped me figure out the answer. Since I cannot upvote the comment I am adding it as an answer here:

CreateFile2 is not a way to bypass the sandbox restrictions. You only get access to the directories that the appxmanifest asks permissions for.

After checking his comment, I debugged my app deeper & was able to see that under certain scenarios, app was trying to read/write to files which were outside of accessible directories.



来源:https://stackoverflow.com/questions/36610931/windows-10-createfile2-error-error-not-supported-in-appcontainer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!