I Take It All Back: Using Windows Installer (MSI) Rollback Actions

Original Link: http://blogs.flexerasoftware.com/installtalk/2011/10/i-take-it-all-back-using-windows-installer-msi-rollback-actions.html#sthash.KIIUKl0s.dpuf

By Robert Dickau

Sometimes an installer just needs to do something that Windows Installer
doesn‘t normally do. When that happens, it‘s a simple matter of writing a custom
action, right? Unfortunately, it‘s not that simple. In this post, we‘ll look at
techniques for reversing changes made by a custom action.

When you launch an installation, it first runs in what‘s called immediate
mode or script-generation mode. As your installer runs in this immediate mode,
it generates an internal to-do list of what it will do on a system—"First I‘ll
install files, then I‘ll create shortcuts, then I‘ll write to the registry, and
then..."—but doesn‘t yet make any system changes.

After immediate mode is done, your installer then switches to something
called deferred mode or script-execution mode. In deferred mode, your installer
performs the actions listed in this script: "Now I‘m installing files, now I‘m
creating shortcuts, now I‘m writing to the registry, and now I‘m..." (The
internal to-do list, or script, is fixed at this point, which is why you can‘t
set property values outside of immediate mode, for example).

As your installer runs in deferred mode, it simultaneously creates a rollback
script describing how to undo changes made by the standard actions. While the
installer installs files, for example, it adds to the rollback script specific
information about what it would have to do to get the system back to its
pre-installer state: "To get the system back to how it was, I‘d need to remove
sample.exe and readme.txt, and also restore the original version of sample.dll
that I replaced." (Windows Installer will also temporarily hold on to resources
such as files that it needs to restore in case of rollback.) If the installer
runs to completion, the rollback script and any cached resources are deleted.
But if the installation encounters a fatal error, or if the user cancels the
installation during deferred mode, the rollback script runs.

A big reason to use standard Windows Installer actions instead of custom
actions is that standard actions handle their own cleanup during uninstallation
or rollback. When you use a custom action, Windows Installer has no idea what
the executable, DLL, InstallScript, etc., that you used did to the system, and
therefore has no idea how to roll back the changes the custom action made. If
your deferred custom action makes any system changes, you should create a
corresponding rollback action.

Immediate mode actions don‘t write to the rollback script, which means that
immediate-mode actions that make system changes won‘t get rolled back if the
installation fails. This is one of several reasons not to make system changes
during immediate mode

(Bonus grammar tip: The noun and adjective are one
word, rollback, while the verb is two words, roll
back
. "If my rollback action runs, it will roll back my changes." An easy
trick is to see if it‘s appropriate to form the past tense by adding -ed: You‘d
say "rolled back", not "rollbacked", and the present tense would be the same
number of words. Same goes for cleanup vs. clean up, setup vs. set up, and so
on. Anyway.)

With InstallShield, you mark a custom action as being a rollback action using
its In-Script Execution setting.

Because the rollback script is created as deferred execution is taking place,
and not beforehand, a rollback action must be placed in the Execute
sequence before the action it rolls back. (Anywhere before
the action being rolled back is fine, but for readability‘s sake and other
reasons, placing the rollback action immediately before the action it rolls back
seems to work best.) If you write a deferred custom action called
"ChangeSomething", its corresponding rollback action "ChangeSomethingBack"
should appear in the sequences immediately before it.

Double Negatives

Things start to get confusing with uninstallation custom actions. Without a
condition, an action always runs, both during the initial installation as well
as maintenance mode, including a complete uninstallation. By setting a condition
on an action, you can specify during which modes it should run: Not
Installed
 for the initial
installation, REMOVE="ALL" for complete
uninstallation, and so on.

The same holds for rollback actions. If you have a deferred action that makes
system changes during the initial installation, you‘ll need a rollback action in
case the installation fails or the user cancels it. You‘ll also probably need an
uninstallation action that reverses the changes during uninstallation;
and also an uninstallation rollback action, in case the
uninstallation fails or the user cancels it, and you need to undo whatever you
just undid. Luckily, the same condition logic applies: if your deferred
uninstallation action uses condition REMOVE="ALL", your
uninstall-rollback action can use the same condition.

And Finally...

If your deferred action saves any temporary data—similar to how the
InstallFiles action temporarily caches files it might need to restore—your
rollback action can clean up that data when it reverses the effects of the
original action. But what if the rollback action never runs?

Windows Installer defines yet another type of action, called
commit action, which runs only if the installation successfully
runs to completion. If a rollback action runs, a commit action won‘t run; and if
a commit action runs, it‘s too late for rollback. Defining an action as a commit
action in InstallShield also involves the In-Script Execution setting, and
follows the same condition logic as other deferred and rollback actions.

To summarize, if you create a custom action that makes changes to a target
system, you might wind up making several others to handle rollback,
uninstallation, uninstallation rollback, and cleanup. If that‘s not a good
argument for avoiding custom actions that duplicate Windows Installer
functionality, I don‘t know what is.

For more information and some hands-on experience—plus information about how
things get trickier with all these deferred, rollback, and commit actions
needing to read property values—come visit us at our Advanced Windows Installer (MSI) Using InstallShield Training
Course
.

I Take It All Back: Using Windows Installer (MSI) Rollback
Actions

时间: 2024-08-03 19:59:31

I Take It All Back: Using Windows Installer (MSI) Rollback Actions的相关文章

安全模式下卸载windows installer打包的软件(转)

安全模式下卸载windows installer打包的软件 起因: 主机系统MAC,虚拟软件Parallels Desktop, 虚拟系统 Win 7. 今天在虚拟机WIN7里面安装了某个软件导致重启时蓝屏,大概是因为这个软件使用了某些驱动组件,而系统是虚拟机不兼容导致的. 蓝屏时不能操作,又无法像物理机一样使用F8进入安全模式,也不能重启,只能卡在蓝屏界面. 想到在蓝屏界面使用 control+option(alt) 呼出PD菜单,在操作中有一个停止,选择停止,然后重启,发现出来了熟悉的 安全

安装SQL2005 SP4补丁报错:无法安装Windows Installer MSP文件

在我们安装完SQL2005数据库后,需要安装SP4补丁时,会出错:无法安装Windows Installer MSP文件 的解决办法 1.开始--控制面板--添加或删除程序,卸载 "Microsoft SQL Server安装程序支持文件(英文)",确定没有残留该文件. 2.将SQL2005SP4补丁包进行复制,并将复制后的文件的格式从原来的.exe执行文件改为.rar的压缩文件.(就是把exe文件压缩) 3.打开压缩文件,查看文件,解压文件中 "hotfixsqlsuppo

【工具】清理Windows Installer冗余文件(支持64位NT6.x系统)

样子: 支持系统: Windows NT 5.x/6.x 32及64位所有系统.需.net framework 2.0运行环境 功能: 清理上述系统中冗余的Windows Installer补丁文件.有如下特点: 高效扫描+清理,并有进度反馈 可选择清理指定文件 可排序 可选择删除到回收站,或直接删除 说明: 类似工具有几个,其中我熟知的是smallfrogs大牛的[Windows Installer 冗余文件清理工具](下文称WIC),事实上在这之前我一直就用他的工具进行相关任务(目前他的官网

关于SQL Server 安装程序在运行 Windows Installer 文件时遇到错误

前几日安装sql server2008r2 的时候碰到这个问题: 出现以下错误: SQL Server 安装程序在运行 Windows Installer 文件时遇到错误. Windows Installer 错误消息: 打开安装日志文件的错误.请验证指定的日志文件位置是否存在,是否可以写入. Windows Installer 文件: D:\qqdownload\cn_sql_server_2014_express_with_advanced_services_x64_exe_3949524\

windows installer 出错问题解决

在卸载程序的额时候,如果出现windows installer出错,可以通过一个Windows Installer CleanUp Utility, 有了Windows Installer CleanUp Utility,您可以轻而易举地删除某个程序地Windows Installer配置信息,选中之后,点击remove即可.可以解决java无法安装问题.

WINDOWS INSTALLER无法启动解决方法

WINDOWS INSTALLER无法启动解决方法 2011-04-13 10:18:32 标签:操作系统 windows 休闲 职场 第一步:使用记事本编写installer.reg文件,内容如下: Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MSIServer] “ImagePath”=- “ImagePath”=hex(2):25,00,53,00,79

安装Microsoft Visual 2010 sp1回滚的错误,无Windows Installer目录

项目需求,安装好Microsoft Visual 2010后,在安装Microsoft Visual 2010 sp1时一直停留在KB983509处, 无法向前,之后无限回滚,导致安装失败,如下图所示,在网上看到很多人写的方法是引用 如下: 大多数的推荐设置是,拷贝VS2010安装包中的vs_setup.msi文件到C:\Windows\Installer文件夹下,并命名为43289.msi 但是想好多人一样,我的电脑里面就没有这个目录,创建也受限,这一步就行不通了. 解决方法如下: 首先进Mi

Window卸载Java出错:无法访问windows installer服务

出于更新Java或者移除JDK,想卸载java(JDK ,JRE, Java Update等),从控制面板卸载和360软件管家卸载都失败.提示:无法访问windows installer服务. 有说下载什么Window installer专用工具和直接删除文件夹的做法都不可取. 解决方法: 打开服务:控制面板---管理工具 --服务  或者 输入DOS命令 services.msc 找到Windows Installer服务,将其启动.

安装JDK出现"Windows Installer程序包有问题,此安装需要的DLL不能运行...(转载)

之前改动了jdk1.6的安装位置,结果卸载的时候无法卸载,重新安装也不行,都提示windows installer 程序包有问题,如图所示 首先确保windows installer服务是开启的,运行services.msc,看看windows installer服务是否启动.先启动看看能否解决.如果是一直启动着的但还是卸载不了,需要借助工具了 解决: 下载Your Uninstaller ,找到jdk 6,选normal mode卸载,它会自动将该软件的注册表信息全部清除干净.再安装就不会提示