如何防止将文件重定向到VirtualStore以读取/写入文件? [英] How to prevent file redirection to VirtualStore for read/write files?

查看:88
本文介绍了如何防止将文件重定向到VirtualStore以读取/写入文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将C#与.net 2.0一起使用

I am using C# with .net 2.0

我将程序数据保存在 C:\ ProgramData \ MyProgramName \ fileName.xml

安装并运行我的应用程序一次后,我将其卸载(在卸载过程中,我将从程序数据"中删除所有文件),然后重新安装该应用程序并运行它.

After installing and running my application one time I uninstalled it (during uninstallation I'm removing all the files from "program data") and then I reinstall the application, and ran it.

奇怪的是,我的应用程序启动时就好像程序数据中的文件存在一样-意味着即使删除了数据文件,我的应用程序中也有旧数据.

The strange thing is that my application started as if the files in program data existed - means, I had old data in my app even though the data file was deleted.

运行时:

File.Exists("C:\ProgramData\MyProgramName\fileName.xml")

我得到真实"的即使我确定该文件不存在.

I got "true" even though I knew for sure that the file does not exist.

当我以管理员身份运行该应用程序时,事情变得奇怪了,然后文件不存在.

The thing became stranger when I ran the application as admin and then the file didn't exist.

经过研究,我发现在没有管理员权限的情况下运行应用程序时,得到的不是:

After a research, I found out that when running my application with no admin privileges instead of getting:

C:\ProgramData\MyProgramName\fileName.xml

我知道

C:\Users\userName\AppData\Local\VirtualStore\ProgramData\MyProgramName\fileName.xml

确实存在以前安装中存在的文件(我显然没有删除,因为我不知道它存在).

and indeed there was a file that existed from the previous installation (that I obviously didn't delete, because I didn't know it existed).

因此,只需指导我如何在没有管理员权限的情况下运行应用程序即可停止运行.

So just guide me how could I stop this when apps running with no admin right.

我不想在VirtualStore文件夹中自动创建任何文件.请讨论阻止这种情况的所有可能方法.

I do not want to create any file automatically in VirtualStore folder. Please discuss all the possible ways to stop this.

推荐答案

首先,问问自己,是否需要为所有用户全局保存此内容?

First, ask yourself, do this need to be globally saved for all users?

如果不是必须的,请将文件保存在应用程序数据"中,可以使用 Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)获取路径,它应始终可靠地扩展为 C:\ Users \ Username \ AppData \ Roaming \ .请注意,尽管此路径对于每个用户而言都是唯一的.

If it doesn't have to be, save the file in Application Data instead, you can get the path with Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), it should always reliably expand to C:\Users\Username\AppData\Roaming\. Do note that this path is unique for each user though.

如果必须的话,您很不走运.没有任何可靠的方法可以在没有特别hacky的任何Windows XP之后的Windows上为没有管理员权限(或UAC)的所有用户存储应用程序数据,例如将数据存储在Public用户中(可能或不可能,我可以.请立即检查).

If you have to, you're out of luck. There is no reliable way to store application data for all users without admin rights (or UAC) on any Windows post-XP that's not extremely hacky, like storing your data in the Public user (which may or may not be possible, I can't check right now).

这篇关于如何防止将文件重定向到VirtualStore以读取/写入文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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