安装制作 (之Inno Setup --- 安装程序前卸载旧版本)
Inno Setup 是一个常用的安装制作工具(www.innosetup.com),如何在安装程序新版本前检查并卸载旧版本呢?
下面代码给我们一条思路,将其插入到.iss文件中即可。
[Code]
var
ResultStr: String;
Names: TArrayOfString;
B: Boolean;
I: Integer;
S: String;
ErrorCode: Integer;
const AppName = '网乐视频分享平台网吧服务器版';
function InitializeSetup(): Boolean;
begin
Result := True;
if RegGetSubkeyNames(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall', Names) then
begin
for I := 0 to GetArrayLength(Names)-1 do
begin
S := Names[i];
SetLength(Names[I], 28);
if AppName=Names[I] then
begin
//注册表中找到了此键
B := RegQueryStringValue(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\'+S, 'UninstallString', ResultStr)
ResultStr := RemoveQuotes(ResultStr);
if B then
begin
//MsgBox('您曾安装过本软件,即将卸载!', mbInformation, MB_OK);
Exec(ResultStr, '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ErrorCode);
Result := False;
end
break;
end
end;
end;
end;
var
ResultStr: String;
Names: TArrayOfString;
B: Boolean;
I: Integer;
S: String;
ErrorCode: Integer;
const AppName = '网乐视频分享平台网吧服务器版';
function InitializeSetup(): Boolean;
begin
Result := True;
if RegGetSubkeyNames(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall', Names) then
begin
for I := 0 to GetArrayLength(Names)-1 do
begin
S := Names[i];
SetLength(Names[I], 28);
if AppName=Names[I] then
begin
//注册表中找到了此键
B := RegQueryStringValue(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\'+S, 'UninstallString', ResultStr)
ResultStr := RemoveQuotes(ResultStr);
if B then
begin
//MsgBox('您曾安装过本软件,即将卸载!', mbInformation, MB_OK);
Exec(ResultStr, '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ErrorCode);
Result := False;
end
break;
end
end;
end;
end;