自动更新Windows应用程序的最佳方法是什么? [英] What is the best way to auto update a windows application?

查看:289
本文介绍了自动更新Windows应用程序的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google Chrome浏览器会自动自动更新每五个小时 .我想在我自己的应用程序中克隆此确切功能.在Windows上实现此功能的最佳方法是什么?

Google Chrome auto updates itself every five hours. I want to clone this exact functionality in my own application. What is the best way to implement this functionality on Windows?

推荐答案

要复制此更新行为,您需要做两件事:

To replicate this update behavior you need two things:

  1. 一个更新程序应用程序,它定期检查更新.如果找到更新,则应自动安装.大多数商业设置创作工具都包含良好的更新程序应用程序.您可以尝试自己编写一个更新程序,但这并不像听起来那样简单.

  1. An updater application which checks for updates regularly. If an update is found it should install it automatically. Most commercial setup authoring tools include good updater applications. You can try writing an updater yourself, but it's not as easy as it sounds.

每用户安装.每用户安装仅将数据写入用户配置文件文件夹(AppData,漫游文件夹等)和HKEY_CURRENT_USER中.没有程序文件或HKEY_LOCAL_MACHINE.

Per-user installations for each of your product versions. A per-user installation writes data only in the user profile folder (AppData, Roaming folder etc.) and HKEY_CURRENT_USER. No Program Files or HKEY_LOCAL_MACHINE.

需要按用户安装,因此您可以静默执行升级.如果按机器安装,则Windows的较新版本将显示提升提示,并且用户将不知道发生了什么.

Per-user installations are required so you can perform the upgrade silently. If the installation is per machine, newer Windows version will show the elevation prompt and the user won't know what's happening.

更新程序

某些更新程序使用服务.对于自动更新,这不是真正的解决方案,因为服务安装需要管理员权限.因此,您的安装过程和后续更新将显示提升提示.

Some updaters use services. For automated updates this isn't a real solution because service installation needs Administrator privileges. So your install process and subsequent updates would show elevation prompts.

另一种方法是使用每个用户的Updater应用程序.它不需要任何高程,可以安装在应用程序文件夹中.这种类型的更新程序可以作为计划任务运行,也可以从您的应用程序内部运行(在应用程序启动时执行).

Another approach is to use a per-user Updater application. It doesn't require any elevation and it can be installed in the application folder. This type of updater can run either as a scheduled task or from within your application (execute it when your application starts).

在两种情况下,您都需要考虑更新程序可能需要自我更新.因此,执行更新的过程必须是一个临时过程(例如,更新程序应用程序的临时副本).它也应该没有高程运行.这就是为什么服务不是一个好主意的原因.它需要在更新之前停止自身,使用临时进程来处理更新,并在完成后重新启动.

In both scenarios you need to consider that the Updater may need to update itself. So the process which performs the update must be a temporary process (for example a temporary copy of the updater application). It also should run without elevation. This is why a service is not such a good idea. It would need to stop itself before the update, use a temporary process which handles the update and start again when finished.

要考虑的其他事项是:

  • 权限问题(如果更新过程需要任何特权或提升权限)
  • 下载位置
  • 更新检测机制(更新程序如何检测是否应安装新版本)

更新

一个常见的误解是更新应该是应用程序文件(如主应用程序EXE).很少出现这种情况,因为更新可能需要覆盖的不仅仅是文件.

A common misconception is that updates should be the application files (like the main application EXE). This is rarely the case because an update may need to overwrite more than just a file.

大多数更新是安装程序包(例如MSI)或补丁程序(MSP).这是最好的方法,因为它们可以处理整个更新逻辑:

Most updates are installation packages (MSI for example) or patches (MSP). This is the best approach because they handle the entire update logic:

  • 检测正在运行的应用程序
  • 更新资源
  • 更新产品信息(控制面板中的快捷方式,程序和功能小程序等)

安装软件包还简化了Updater应用程序.使用这种类型的更新,更新程序仅需要检测可用的更新,下载并执行.

Installation packages also simplify the Updater application. With this type of updates the Updater needs only to detect available updates, download them and execute them.

更新以两种方式起作用:

Updates works in two ways:

  • major upgrades: the old version is completely uninstalled before the new one is installed
  • minor upgrades: the old version is patched

Windows Installer对它们两者都有很好的支持,因此您可以使用 MSI软件包 MSP补丁 .它还支持静默安装,因此Updater所需要做的就是使用命令行参数执行该软件包.

Windows Installer has great support for both of them, so you could use MSI packages and MSP patches. It also supports silent installations, so all your Updater needs to do is execute the package with a command line parameter.

这些软件包还通过支持按用户或按计算机安装. ALLUSERS 属性.

These packages also support per-user or per-machine installations through ALLUSERS property.

更新分发

确定更新程序和一些更新程序包后,还需要一种分发机制:

After you decide on an Updater and some update packages, you also need a distribution mechanism:

  • 一种通知更新程序可用更新的方式(例如服务器上的更新信息文件)
  • 一种检测更新是否已安装(因此仅安装一次)的方法

所有这些都不是一件容易的事.这就是为什么许多产品使用第三方更新程序的原因.甚至某些商业设置创作工具都可以为您的软件包提供更新程序.

All of this is not very easy. This is why a lot of products use third-party Updaters. Even some commercial setup authoring tools offer Updaters for your packages.

自定义更新程序通常由拥有很多产品的大型公司使用,因为投资对于他们来说是值得的.

A custom updater is mostly used by very large companies with a lot of products, because the investment is worth it for them.

这篇关于自动更新Windows应用程序的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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