gpt4 book ai didi

windows - 使用 NSIS 将应用程序文件安装到标准 Windows 用户

转载 作者:可可西里 更新时间:2023-11-01 09:52:44 39 4
gpt4 key购买 nike

我有一个应用程序需要 SQLite 数据库才能运行。在我的 NSIS 脚本中,数据库被复制到用户的 Local/AppData 文件夹中。如果安装该程序的用户是管理员用户,这就可以正常工作。

但是,如果标准用户尝试安装该程序,安装程序会要求输入管理员密码(因为标准用户无法在 Windows 上安装程序)并且正在安装的用户现在被切换为管理员,导致数据库安装在管理员 Local/AppData 文件夹中,而不是实际用户的 AppData 文件夹中。

因此,实际上,当标准用户尝试运行该程序时,它找不到数据库。

我不确定如何处理这种情况(最佳实践,如果有的话)并且找不到回答它的问题。

安装程序是否应该将数据库放到公共(public)场所,例如 AllUsers,并在第一次运行时将数据库从那里复制到他们自己的 AppData 文件夹中?

allusers 文件夹的问题在我看来是任何人都可以窥视它并可能删除文件。

最佳答案

标准用户可以安装应用程序。在$LocalAppdata\Programs\MyApp(FOLDERID_UserProgramFiles)下安装程序,在HKCU下写入卸载信息。 NSIS 具有特殊的 SHCTX 注册表根目录(由 SetShellVarContext 控制),如果您想在一个安装程序中支持两种类型的安装模式,它可以帮助实现这一点。

如果您想强制用户始终提升为管理员权限,那么推荐的方法确实是将数据库的模板/基本版本存储在 AllUsers 应用程序数据(在 Vista+ 中称为 ProgramData)(SetShellVarContext all + $AppData) 或 Common ProgramFiles ($COMMONFILES) 文件夹,并让您的应用程序在首次运行时为特定用户创建一个副本。只有管​​理员可以删除这些位置中的文件。大多数用户将具有读取权限,但这无关紧要,因为文件不应包含用户特定信息。

您可以在 Certification requirements for Windows desktop apps 中找到这些建议或较旧的 Windows Logo requirements文档:

10.3 Your app data, which must be shared among users on the computer, should be stored within ProgramData

10.4 Your app’s data that is exclusive to a specific user and that is not to be shared with other users of the computer, must be stored in Users\\AppData

10.6 Your app must write user data at first run and not during the installation in “per-machine” installations

When the app is installed, there is no correct user location in which to store data. Attempts by an app to modify default association behaviors at a machine level after installation will be unsuccessful. Instead, defaults must be claimed on a per-user level, which prevents multiple users from overwriting each other's defaults.

关于windows - 使用 NSIS 将应用程序文件安装到标准 Windows 用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31641818/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com