Install Shield Silent Installs

本文介绍如何利用InstallShield实现软件的静默安装与卸载。通过创建响应文件记录安装选项,可以实现无需用户交互的后台安装过程。此外,还提供了一种Python脚本方法来解决每次安装分配不同GUID导致的卸载问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

Install Shield has this nifty feature of being able to install packages in silent mode. This means that you can run setup.exe from the command prompt and it will install in the background with no user interaction. This is very useful if you want to test your installation. If you use some sort of continuous integration system (and you should if you don't) then you could download the latest installer do a silent install and run some tests against the program that is installed, then silent uninstall it all automat(g)ically.

To be able to do silent installs/un-installs you first need to record a response file that contains all the choices for the install shield dialogs.

To record the response file;

setup.exe -r

This will be like a normal install done manually. Follow it through like you would in any normal installation. After the installer exits, the response file should be at C:\Windows\setup.iss

Next time around you can do a silent install by running

setup.exe -s -f1

I'm paranoid so I use the absolute path to the response file. There is no space between "-f1" and the path to setup.iss. Note that, when you run the above command to silent install, the command will seem to exit immediately but if you check Task Manager you should see setup.exe (possibly 2 of them) running.

Silent un-installation is pretty much the same. You need to create a response file first. To do this run the following;

setup.exe -r -uninst -removeonly

This will again create a setup.iss file in C:\Windows I usually rename the uninstall response file as uninst.iss. Now you can do silent uninstallation by running;

setup.exe -s -uninst -removeonly -f1

Some installers might install the program under different GUID's each time you install it. If this is the case I have found that the above command for uninstallation doesn't work, as Install Shield doesn't know what to uninstall. The solution is to work out the UninstallString from the Registry (which is what Windows uses to uninstall the program via Add/Remove Software).

Here is a python script that uses the registry module (http://pypi.python.org/pypi/registry/) to find out the full UninstallString. You first need to manually find this string in your registry by looking under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall so that you can pass into this function a unique string that is present in the UninstallString of your program

EDIT: the following script is quite ugly actually. I have a new version in which I use regobj it makes things easier.

import registry
def findUninstallStr(q):
    ''' q: some unique string that appears in the UninstallString value '''
    uninstallKey = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
    for subkey in registry.GetSubKeys(uninstallKey):
        for (valuename, value, valuetype) in registry.GetKeyValues("%s\%s" %(uninstallKey, subkey)):
            if 'UninstallString' == unicode(valuename) and q in unicode(value):
                uninstallString = value
                return r"%s" %unicode(uninstallString)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值