CreateFile()/ fopen()faild,错误访问被拒绝(5) [英] CreateFile()/ fopen() faild with Error Access Denied (5)

查看:701
本文介绍了CreateFile()/ fopen()faild,错误访问被拒绝(5)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我在dll中为资源管理器编写了一个预览程序。

prevhost.exe具有与用户。

我想在临时目录中写一个临时文件

(或任何其他目录),但如果我调用了

函数CreateFile(或者fopen写

或将任何内容附加到现有文件中,函数失败

,错误5 - 访问被拒绝。



读取文件并不会失败。



谢谢

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

推荐答案

在预览处理程序中 - 我只能写一个LocalLow目录喜欢

C:\ Users \<用户名> \ AppData \ LocalLow \< temp>



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

thanks


append:如果文件已被使用,您可能会收到拒绝访问错误(好的,如果共享它可以工作)。因此,请检查您要写入的文件是否尚不存在。

您确定要写入正确的临时目录吗?用户不得写入C:\ Windows\Temp ...使用Windows资源管理器检查您是否可以手动创建文件以创建临时文件。
"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.


如上所述在解决方案#1中,如果文件在另一个进程中以写或其他非共享访问方式打开,则可以获得此信息。当您开发软件时,通常会编写一个程序版本,它不会关闭文件或正确终止...所以程序的旧错误版本可能会打开文件。



几种解决方法:

- 使用随机文件名写入/追加,这样每次运行程序时都会打开一个新文件

- 重新启动



调试好程序并正常工作后,更改逻辑以使用静态文件名。
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.


这篇关于CreateFile()/ fopen()faild,错误访问被拒绝(5)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆