Click here to Skip to main content
13,090,519 members (52,773 online)
Rate this:
Please Sign up or sign in to vote.

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 10-May-12 20:34pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

In the preview-handler - I can only write in a LocalLow-directory like

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

"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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 21 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100