Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I wrote a previewhandler for the explorer inside a dll.
The prevhost.exe has the same rights as the User.
I want to write a temporary file in the temporary directory
(or any other directory), but if I called the
function CreateFile() or fopen to write
or append anything to an existing file the function failed
with the error 5 - access denied.

Reading a file doesn't fail.

thank you
Posted

In the preview-handler - I can only write in a LocalLow-directory like
C:\Users\<username>\AppData\LocalLow\<temp>

thanks
 
Share this answer
 
"append": if a file is already in use, you'll likely get an access denied error (ok, in case of sharing it can work). Hence check that the file you want to write does not yet exist.
Are you sure that you write to the correct temporary directory? A user must not write to C:\Windows\Temp... Check with Windows explorer that you can create a file manually where you want to create your temporary file.
 
Share this answer
 
As stated in solution #1, you can get this if the file is open with write or otherwise unshared access in another process. When you are developing software, it is common to write a version of your program which does not close files or terminate properly ... so an older errant version of your program could be holding the file open.

Several workarounds:
- Use a randomized filename to write/append to, so that you are opening a new file every time you run your program
- Reboot

Once you have your program debugged and working properly, change the logic to use the static filename.
 
Share this answer
 

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