本文介绍了FOPEN创造系统驱动文件时,无形之中失败(C:\\)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我尝试创建一个使用的fopen一个文件,的fopen充当如果文件已经被正确打开,它具有完全访问权限,但它实际上并没有创建该文件。我的程序不具有系统根文件夹的写权限,因为它需要管理员权限写有,但为什么不是fopen()函数发出任何错误?

Whenever I try to create a file using fopen, fopen acts as if the file has been opened properly and that it has full access to it, but it doesn't actually create the file. My program doesn't have write access to the system root folder because it needs admin access to write there, but why isn't fopen() giving any errors?

不知道如何判断是否有错误或不?当我试图在一个受保护的目录中打开该文件,获取返回的文件句柄是完全一样的,当我在一个目录,我有写权限打开一个文件。

Any idea how to tell if there's an error or not? The file handle that gets returned when I'm trying to open the file in a protected directory is exactly the same as when I open a file in a directory where I have write access.

我曾与各种不同版本的fopen(FOPEN,_wfopen,_wfopen_s),但它们都具有相同的输出尝试这个。

I've tried this with the various different versions of fopen (fopen, _wfopen, _wfopen_s) but they all have the same output.

有趣的是,GetLastError()返回ERROR_ALREADY_EXISTS。

Interestingly enough, GetLastError() returns ERROR_ALREADY_EXISTS.

这里的code,我使用:

Here's the code that I'm using:

FILE *FileHandle; 
DWORD error = _wfopen_s(&FileHandle, L"\\filename.txt", L"a");
Win32Error = GetLastError();

if (error != 0 || FileHandle == NULL)
{
    //Throw error
}
else 
{
    //write to file
    //close file
}

编辑:指出,结果收到的,因为虚拟化。有谁知道如何禁用此功能?

As rerun pointed out, the file is getting created in %APPDATA% because of virtualization. Does anyone know how to disable this feature?

推荐答案

这可能与虚拟商店做。看看这里一些信息。

This might have to do with the virtual store. Take a look here for some info.

这篇关于FOPEN创造系统驱动文件时,无形之中失败(C:\\)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 18:42