您的位置:首页 > 其它

Inno_setup制作升级包必须面临的几个问题

2015-09-27 23:49 369 查看

Inno_setup制作升级包必须面临的几个问题

分类: c/c++/GamingAnyWhere JavaScript linux shell基础知识 2013-12-18 22:14 1496人阅读 评论(0) 收藏 举报
Inno_setup升级包注册表控制面板版本
这两天的时间一直在制作应用程序的升级包,期间碰到一些问题这里一并记录下来,相信这是制作升级包必须面临和解决的问题:

1. 升级包安装程序如何不再产生新的安装、卸载程序

Inno_setup中AppId是用来标识某个应用程序的唯一标识,因此升级包中的AppId字段应该和原始安装程序的AppId相同。

CreateUninstallRegKey字段,改值设置为no则安装程序将不会在控制面板的“添加/删除程序”中再创建一个。当这个关键字设置为 no时,UpdateUninstallAppName通常也设置为 no。

UpdateUninstallAppName如果为 yes, 当添加到一个已存在的卸载记录时,安装程序将以当前的安装程序的 AppName 替换在卸载记录中的 AppName。卸载记录中的 AppName决定了卸载程序显示的标题。如果你的安装程序只是一个升级或附加到一个已存在的程序,并且你不想改变卸载程序的标题,那么你可以设置该值为 no。

2. 如何检测以前的应用程序正在运行

判断某个应用程序是否正在运行,这里可以采用两种方式:一种是应用程序的进程是否正在运行;一种是通过窗口名称来检测。采用第一种方式时要引入ISTask.dll文件(它通常可以在Inno_setup安装包里面找到),实例代码如下:

1) 通过进程检测是否正在运行

首先确保ISTask.dll文件和脚本文件位于同一目录:

// 卸载时判断浏览器是否正在运行
function InitializeUninstall(): Boolean;
var
iehWnd, ffhWnd, chrhWnd, b360hWnd, safhWnd, i: Integer;
begin
result:=true;
iehWnd := FindWindowByClassName('IEFrame');
ffhWnd := FindWindowByClassName('MozillaWindowClass');
b360hWnd := FindWindowByClassName('360se6_Frame');
chrhWnd := FindWindowByClassName('Chrome_WidgetWin_1');
safhWnd := FindWindowByClassName('{1C03B488-D53B-4a81-97F8-754559640193}');
i := 0;

while (iehWnd>0) or (ffhWnd>0) or (b360hWnd>0) or (chrhWnd>0) or (safhWnd>0) do
begin
if i > 0 then
begin
Msgbox('请确保所有浏览器都已关闭!', mbInformation, MB_OK);
end;

if Msgbox('插件更新程序检测到浏览器正在运行。'  #13#13 '请您先关闭所有浏览器,单击“是”继续更新,否则按“否”退出安装', mbConfirmation, MB_YESNO) = idNO then
begin
Result:=false;
iehWnd :=0;
ffhWnd :=0;
b360hWnd :=0;
chrhWnd :=0;
safhWnd :=0;
end else begin
Result :=true;  //卸载程序继续
iehWnd := FindWindowByClassName('IEFrame');
ffhWnd := FindWindowByClassName('MozillaWindowClass');
b360hWnd := FindWindowByClassName('360se6_Frame');
chrhWnd := FindWindowByClassName('Chrome_WidgetWin_1');
safhWnd := FindWindowByClassName('{1C03B488-D53B-4a81-97F8-754559640193}');
end;
i := i+1;
end;
end;

// 检测应用服务是否正在使用  added by houqd 2013/12/17
// 该函数利用FindWindowByWindowName(),只能通过窗口的名字来判断
// 不适合现在的情况,采用另一种方式判断后台进程是否正在进行
function ifRunningDesktop():Boolean;
var
isRunning:Integer;
cycleCount:Integer;
begin
Result:=true;
cycleCount:=0;
isRunning:=FindWindowByWindowName('有道词典');
while isRunning <> 0 do
begin
if cycleCount > 0 then
begin
Msgbox('请确保客户端已关闭!', mbInformation, MB_OK);
end;
if MsgBox('升级程序检测到客户端正在运行。' #13#13 '您必须先关闭客户端然后单击“是”继续安装,或按“否”退出安装!',mbConfirmation, MB_YESNO) = idNO then
begin
Result:=false;
isRunning:=0;
end else begin
Result:=true;
isRunning:=FindWindowByWindowName('VSODesktop');
end;
cycleCount:=cycleCount +1 ;
end;
end;

// 判断某个进程是否正在运行,利用安装包里面自带的ISTask.dll插件
function RunTask(FileName: string; bFullpath: Boolean): Boolean;
external 'RunTask@files:ISTask.dll stdcall delayload';

function ifBrowserIsRunning():Boolean;
var
iehWnd, ffhWnd, chrhWnd, b360hWnd, safhWnd, i: Integer;
begin
iehWnd := FindWindowByClassName('IEFrame');
ffhWnd := FindWindowByClassName('MozillaWindowClass');
b360hWnd := FindWindowByClassName('360se6_Frame');
chrhWnd := FindWindowByClassName('Chrome_WidgetWin_1');
safhWnd := FindWindowByClassName('{1C03B488-D53B-4a81-97F8-754559640193}');

if (iehWnd>0) or (ffhWnd>0) or (b360hWnd>0) or (chrhWnd>0) or (safhWnd>0) then
begin
Result:=true;
end else begin
Result:=false;
end;
end;

// 检测vsodesktop进程是否正在运行,即正在打开这vso应用软件
// added by houqd 2013/12/18
function ifVsoIsRunning():Boolean;
var
pstate:Boolean;
begin
Result:= RunTask('VSODesktop.exe', false);
end;

// 升级包通过修改注册表,更改控制面板中已安装软件的版本信息
// added by houqd 2013/12/18
function updateVersion():Boolean;
var
ResultStr:String;
nDisplayName:String;
nVersion:String;
begin

Result:=true;
nDisplayName:='{#PreDisplayName}'+'{#MyAppVersion}';
nVersion:='{#MyAppVersion}';

// 修改版本信息
if RegQueryStringValue(HKLM,'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{C77BFCB0-66A4-4D04-82D9-FF74356FA0B1}_is1','DisplayName',ResultStr) then
begin
if nDisplayName <> ResultStr then
begin
RegWriteStringValue(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{C77BFCB0-66A4-4D04-82D9-FF74356FA0B1}_is1', 'DisplayName', nDisplayName);
end;
end;

if RegQueryStringValue(HKLM,'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{C77BFCB0-66A4-4D04-82D9-FF74356FA0B1}_is1','DisplayVersion',ResultStr) then
begin
if nVersion <> ResultStr then
begin
RegWriteStringValue(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{C77BFCB0-66A4-4D04-82D9-FF74356FA0B1}_is1', 'DisplayVersion', nVersion)
end;
end;
end;

// 升级包通过修改注册表,更改控制面板中已安装软件的显示图标
// added by houqd 2013/12/18
function updateDisplayIcon():Boolean;
var
ResultStr:String;
nDisplayIcon:String;
installLocation:String;
begin
Result:=true;

RegQueryStringValue(HKLM,'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{C77BFCB0-66A4-4D04-82D9-FF74356FA0B1}_is1','InstallLocation',installLocation);
nDisplayIcon:=installLocation+'VSODesktop.exe';

// 如果DisplayIcon该键值存在则说明它原本就有图标,现在要对比更新
if RegQueryStringValue(HKLM,'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{C77BFCB0-66A4-4D04-82D9-FF74356FA0B1}_is1','DisplayIcon',ResultStr) then
begin
if nDisplayIcon <> ResultStr then
begin
RegWriteStringValue(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{C77BFCB0-66A4-4D04-82D9-FF74356FA0B1}_is1', 'DisplayIcon', nDisplayIcon)
end;
end else begin
RegWriteStringValue(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{C77BFCB0-66A4-4D04-82D9-FF74356FA0B1}_is1', 'DisplayIcon', nDisplayIcon)
end;
end;

rdpFileExsits:=FileSearch('rdp.tmp',ExpandConstant('{app}'));    // 如果文件存在则返回绝对路径,如果不存在则返回空
      if rdpFileExsits = '' then
      begin
         Exec(ExpandConstant('{cmd}'), '/c wmic qfe get hotfixid | find "KB2592687" > '+ExpandConstant('{tmp}\rdp.tmp'), '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
         FileCopy(ExpandConstant('{tmp}\rdp.tmp'),ExpandConstant('{app}\rdp.tmp'),false);
      end;


View Code

加油,坚持每天的学习,少年!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: