Vim*_*987 82 installer inno-setup
我正在使用Inno Setup来创建安装程序.
我希望安装程序自动卸载以前安装的版本,而不是覆盖它.我怎样才能做到这一点?
Cra*_*een 104
我使用了以下内容.我不确定这是最简单的方法,但它有效.
这种用途{#emit SetupSetting("AppId")}依赖于Inno Setup Preprocessor.如果您不使用它,请直接剪切并粘贴您的App ID.
[Code]
/////////////////////////////////////////////////////////////////////
function GetUninstallString(): String;
var
sUnInstPath: String;
sUnInstallString: String;
begin
sUnInstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#emit SetupSetting("AppId")}_is1');
sUnInstallString := '';
if not RegQueryStringValue(HKLM, sUnInstPath, 'UninstallString', sUnInstallString) then
RegQueryStringValue(HKCU, sUnInstPath, 'UninstallString', sUnInstallString);
Result := sUnInstallString;
end;
/////////////////////////////////////////////////////////////////////
function IsUpgrade(): Boolean;
begin
Result := (GetUninstallString() <> '');
end;
/////////////////////////////////////////////////////////////////////
function UnInstallOldVersion(): Integer;
var
sUnInstallString: String;
iResultCode: Integer;
begin
// Return Values:
// 1 - uninstall string is empty
// 2 - error executing the UnInstallString
// 3 - successfully executed the UnInstallString
// default return value
Result := 0;
// get the uninstall string of the old app
sUnInstallString := GetUninstallString();
if sUnInstallString <> '' then begin
sUnInstallString := RemoveQuotes(sUnInstallString);
if Exec(sUnInstallString, '/SILENT /NORESTART /SUPPRESSMSGBOXES','', SW_HIDE, ewWaitUntilTerminated, iResultCode) then
Result := 3
else
Result := 2;
end else
Result := 1;
end;
/////////////////////////////////////////////////////////////////////
procedure CurStepChanged(CurStep: TSetupStep);
begin
if (CurStep=ssInstall) then
begin
if (IsUpgrade()) then
begin
UnInstallOldVersion();
end;
end;
end;
Run Code Online (Sandbox Code Playgroud)
备择方案
另请参阅此博客文章"版本比较的Inno安装脚本示例",它更进一步,并读取任何以前安装的版本的版本号,并将该版本号与当前安装包的版本号进行比较.
Oli*_*sen 25
在给定AppId(即您AppID在[Setup]-section中使用的值)时,您应该能够从注册表中读取卸载字符串.它可以在下面找到Software\Microsoft\Windows\CurrentVersion\Uninstall\{AppId}\(可以是HKLM或者HKCU,最好检查两者){AppId}应该用你使用的实际值代替.查找UninstallString或QuietUninstallString值并使用该Exec函数从InitializeSetup()事件函数运行它.
更新:使用[Run]-section条目删除了非工作替代解决方案{uninstallexe}- 感谢所有指出这一点的评论者!
使用Inno Setup时,除非该版本由其他安装程序安装,否则没有理由卸载以前的版本.否则,将自动处理升级.
如果您"只想删除旧图标"(因为您的图标已更改/更新),您可以使用:
; attempt to remove previous versions' icons
[InstallDelete]
Type: filesandordirs; Name: {group}\*;
Run Code Online (Sandbox Code Playgroud)
这是在"安装开始时"运行,所以基本上删除旧图标,完成后仍然会在那里安装新图标.
我只是在每次安装时执行此操作"万一有任何更改"图标明智(无论如何都会重新安装).
| 归档时间: |
|
| 查看次数: |
72010 次 |
| 最近记录: |