Call CreateFileW() function return error 5 on UWP APP

zev young 20 Reputation points
2023-08-10T02:43:28.0833333+00:00

Hi Microsoft team,

I am developing a UWP app, the function is connected to my driver.

I try the way below.

User's image

But I get error=5, so can you help me?

Developer technologies Universal Windows Platform (UWP)
{count} votes

Accepted answer
  1. Junjie Zhu - MSFT 21,646 Reputation points
    2023-08-10T05:34:00.5233333+00:00

    Hi @zev young ,

    Welcome to Microsoft Q&A!

    Error code 5 (ERROR_ACCESS_DENIED), it appears when the user does not have sufficient permission to access the requested file or location. UWP runs in a sandbox and cannot directly access files like desktop applications.

    CreateFileW() only support desktop apps, it's not supported in UWP. If you want to create file in UWP, you can use Windows.Storage.StorageFolder.CreateFileAsync. For more information you can refer to the document Create, write, and read a file.

    If you want to access files outside the UWP application, you need to use Filepicker or open file access permissions. Please note that after using the broadFileSystemAccess capability, users need to manually open the permission in the App setting.

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.