Click here to Skip to main content
15,351,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
WriteFile return access denied?

while i providing admin privileges

please help me for this.

C++
HANDLE hCD = CreateFile (file_Name, GENERIC_READ|GENERIC_WRITE,
						 FILE_SHARE_READ|FILE_SHARE_WRITE,
						 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
						 NULL);

WriteFile (hCD, Buffer, Size, &bytesWritten, NULL);

its fails with access denied.


thanks in advance.

What I have tried:

WriteFile return access denied?

while i providing admin privileges

please help me for this.

C++
HANDLE hCD = CreateFile (file_Name, GENERIC_READ|GENERIC_WRITE,
						 FILE_SHARE_READ|FILE_SHARE_WRITE,
						 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
						 NULL);

WriteFile (hCD, Buffer, Size, &bytesWritten, NULL);

its fails with access denied.


thanks in advance.
Posted
Updated 20-Dec-21 21:59pm

Start by checking that the file and the whole path it describes exists, and that the necessary access permissions apply to the whole path. if this is a network share, you will need to ensure that write access for the connection user is available as well.

Then check the app user: depending on how your app runs, it may not be the same user you would normally apply. For example, a Service does not run under a standard user account and can't access user data unless specifically permitted to.

If all of that looks right, then start looking to see if the file is already open - is there an exclusive lock on the file elsewhere in your app that hasn't been closed, or is some other app accessing the file at the same time? Does this occur every time, or the second time you do something, or ... you know the drill.

Sorry, but we can't help you - this requires access to your system that we just don't have; a tiny fragment of code is nowhere near enough!
   
You already posted this question at WriteFile return access denied? - C / C++ / MFC Discussion Boards[^]. And you have been a CodeProject member long enough to know that you should not repost the same questions.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900