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

Install application files to standard windows user using NSIS

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

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

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

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

安装程序是否应该将数据库放入 public 位置,例如 AllUsers,然后首先 运行 将数据库从那里复制到他们自己的 AppData 文件夹中?

在我看来,allusers 文件夹存在问题,任何人都可以查看并删除文件。

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

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

您可以在 Certification requirements for Windows desktop apps or the older 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.