我正在尝试编写一个可以在 Windows Vista 和 XP 上运行的安装程序(通过创建 .vdproj)。 我发现的唯一一件事是,当我尝试在 Vista 上运行它时,我包含在安装程序中的文件是以用户组的只读权限安装的。 这是一个问题,因为应用程序需要读取/写入这些文件。 我能够让它工作的唯一方法是“以管理员身份运行”或实际更改权限。 有谁知道如何使这些文件可供任何人写入? 谢谢。
I am trying to write an installer (by creating a .vdproj) that will work on both Windows Vista and XP. The only thing I am finding is that when I try to run it on Vista, the files that I include in the installer are installed with Read-only permissions for the Users groups. This is a problem because the application needs to read/write from these files. The only way I have been able to get it to work is to either "Run as Administrator" or actually change the permissions. Does anyone know how to make these files be open to anyone to write? Thanks.
发布评论
评论(2)
Program Files 文件夹及其内容仅供标准用户读取。 这是设计使然,您会发现Windows XP 上也是如此。只是在 Windows XP 上,很多人一直以管理员权限运行,您可能会逃脱用它。 如果您想将您的应用程序分发到商业环境中,您很快就会发现它也无法在 XP 上运行。
如果标准用户需要写访问权限,解决方案是不要将文件放置在程序的可执行文件夹中。 将它们放在“应用程序数据”文件夹中。 对于大多数 XP 机器,该位置位于:
C:\Documents And Settings\All Users\Application Data\Your App
但是,情况并非总是如此,而且在 Vista 上还是有点不同,因此请确保通过编程环境提供的机制获取该路径。 在 .Net 中,您可以使用
Environment.GetFolderPath()
函数。The Program Files folder and it's contents are read only for standard users. This is by design, and you'll find that this is the case on Windows XP as well. It's just that on windows xp, so many people run with administrator rights all the time that you might get away with it. If you ever want to distribute your app into a business environment, you'll soon find that it won't work on XP there, either.
The solution is to NOT place files in the program's executable folder if standard users will need write access. Put them in the Application Data folder instead. For most xp machines, that will be here:
C:\Documents And Settings\All Users\Application Data\Your App
However, that won't always be the case and it's a little different on Vista anyway, so make sure you get that path via the mechanism provided by your programming environment. In .Net, you can use the
Environment.GetFolderPath()
function.为 Joel 的回答添加一些细节:
在 Win2K 和 XP 中,CSIDL_APPDATA 应该用于每用户漫游。 在 Vista 中,这是 FOLDERID_RoamingAppData。
在 Win2K 和 XP 中,CSIDL_LOCAL_APPDATA 应用于每用户、非漫游。 在 Vista 中,这是 FOLDERID_LocalAppData。
在Win2K和XP中,CSIDL_COMMON_APPDATA应该用于每台机器,即应用程序的所有用户。 在 Vista 中,这是 FOLDERID_ProgramData。
注意,最后一个文件夹通常对非管理员非高级用户是只读的。 建议的解决方案是在应用程序安装期间创建一个读/写子文件夹。
编辑:要使用托管代码获取这些常量在特定计算机上的实际位置,请尝试使用定义的常量 System.Environment.GetFolderPath 此处。 另一个有用的链接是 此处。
To add some detail to Joel's answer:
In Win2K and XP, CSIDL_APPDATA should be used for per-user, roaming. In Vista, this is the FOLDERID_RoamingAppData.
In Win2K and XP, CSIDL_LOCAL_APPDATA should be used for per-user, non-roaming. In Vista, this is FOLDERID_LocalAppData.
In Win2K and XP, CSIDL_COMMON_APPDATA should be used for per-machine, i.e. all users of an application. In Vista, this is FOLDERID_ProgramData.
NB This last folder is normally read-only to non-admin non-power users. The recommended solution to this is to create a read/write sub-folder during app installation.
EDIT: To get the actual locations of these constants on a specific machine using managed code, try System.Environment.GetFolderPath with the constants defined here. Another useful link is here.