写入“ProgramData”文件夹(W7 和 Vista).NET
我将我的应用程序安装在“Program Files”目录下。我在“ProgramData”目录下安装数据:
Environment.SpecialFolder.CommonApplicationData
在programData中我创建了文件夹来保存数据。示例:
C:\ProgramData\MyApp\MyData\这里我有文件和文件夹
在XP下一切运行正常。但在 Vista 或 W7 操作系统下不行。
我可以读取此目录中的文件,但无法写入文件,无法创建新文件等。用户以管理员身份登录。
我可以在哪里不受限制地存储数据?我需要将数据存储在所有用户可见的文件夹中
编辑:
我的 app.manifest 文件中有以下代码:
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- Opciones del manifiesto de Control de cuentas de usuario
Si desea cambiar el nivel de Control de cuentas de usuario de Windows, reemplace el
nodo requestedExecutionLevel por alguno de los siguientes.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
Si desea utilizar la virtualización de archivos y del Registro para la compatibilidad
con versiones anteriores, elimine el nodo requestedExecutionLevel.
-->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
</asmv1:assembly>
I install my app under "Program Files" directory. And I install data, under "ProgramData" directory:
Environment.SpecialFolder.CommonApplicationData
In programData I have created folder to save data. Example:
C:\ProgramData\MyApp\MyData\here I have files and folders
Under XP all runs fine. But not under Vista or W7 OS.
I can read files in this directory, but I can not write files, I can not create new files, etc. The user is logged as Admin.
Where I can store data without restrictions? I need store data in a folder visible for all users
EDITED:
I have this code in my app.manifest file:
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- Opciones del manifiesto de Control de cuentas de usuario
Si desea cambiar el nivel de Control de cuentas de usuario de Windows, reemplace el
nodo requestedExecutionLevel por alguno de los siguientes.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
Si desea utilizar la virtualización de archivos y del Registro para la compatibilidad
con versiones anteriores, elimine el nodo requestedExecutionLevel.
-->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
</asmv1:assembly>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可以在此处找到有关可以存储程序数据的不同位置的易于理解的说明:
http://blogs.msdn.com/cjacks/archive/2008/02/05/where-should-i-write- program-data-instead-of-program-files.aspx
至于 ProgramData,它说:
An easy to understand explanation of the different places you can store program data can be found here:
http://blogs.msdn.com/cjacks/archive/2008/02/05/where-should-i-write-program-data-instead-of-program-files.aspx
As regards ProgramData, it says:
这是UAC的事情。您以管理员身份运行程序,以便在此 SpecialFolder 中创建/删除文件/文件夹。
This is a UAC thing. You have your program run as administrator for creating/deleting files/folders in this SpecialFolder.
乍一看,这是一个概念问题:
您不应该使用“ProgramData”目录,而应该使用一些用户特定的文件。
所需的安装数据应安装在“程序文件”或注册表中。
it is a conceptual issue at first look:
You should NOT use the "ProgramData" directory but some user specific files.
Needed installation data should installed in the "program files" or in the registry.