|
正式会员享受无限制浏览网站功能和高速网盘下载,赶快加入本站吧!
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- [Files]; 安装前判断进程,dll文件放在inno的安装目录中
- Source: "compiler:ISTask.dll"; DestDir: "{tmp}"; Flags: deleteafterinstall dontcopy
- Source: "compiler:ISTask.dll"; DestDir: "{app}";
- Source: "compiler:psvince.dll"; DestDir: "{tmp}"; Flags: deleteafterinstall dontcopy
- Source: "compiler:psvince.dll"; DestDir: "{app}";
- [Code]
- //安装前判断是否有进程正在运行
- // PSVince控件无法检测到64位exe程序的进程,使用下面的函数可以解决。
- function IsAppRunning(const FileName: string): Boolean;
- var
- FWMIService: Variant;
- FSWbemLocator: Variant;
- FWbemObjectSet: Variant;
- begin
- Result := false;
- FSWbemLocator := CreateOleObject('WBEMScripting.SWBEMLocator');
- FWMIService := FSWbemLocator.ConnectServer('', 'root\CIMV2', '', '');
- FWbemObjectSet := FWMIService.ExecQuery(Format('SELECT Name FROM Win32_Process Where Name="%s"',[FileName]));
- Result := (FWbemObjectSet.Count > 0);
- FWbemObjectSet := Unassigned;
- FWMIService := Unassigned;
- FSWbemLocator := Unassigned;
- end;
- function RunTask(FileName: string; bFullpath: Boolean): Boolean;
- external 'RunTask@files:ISTask.dll stdcall delayload';
- function KillTask(ExeFileName: string): Integer;
- external 'KillTask@files:ISTask.dll stdcall delayload';
-
- function InitializeSetup():boolean;
- var
- IsRunning: boolean;
- // 第二步,安装时判断客户端是否正在运行,注意:使用IsAppRunning函数(已在前面定义),
- //可以在32和64位系统下检测32和64位进程,但还是不能识别进程的版本,如果有多版本的话。
- begin
- Result:= true;//安装程序继续
- if not RegKeyExists(HKEY_LOCAL_MACHINE, 'SOFTWARE\McNeel\Rhinoceros\5.0x64') then
- begin
- MsgBox('该系统未检测软件程序,请先行安装软件程序!', mbInformation, MB_OK);
- Result := False;
- end;
- IsRunning:= IsAppRunning('rhino.exe');
- while IsRunning do
- begin
- if MsgBox('安装检测到 软件 正在运行!' #13#13 '先关闭所有软件之后,再单击“确定”继续安装,否则按“取消”退出安装!', mbConfirmation, MB_OKCANCEL) = IDOK then
- begin
- IsRunning:= IsAppRunning('rhino.exe');
- Result:= true;
- end else begin
- IsRunning:= false;
- Result:= false;//安装程序退出
- Exit;
- end;
- end;
- end;
-
- begin
- Result:= true;//安装程序继续
- if RunTask('rhino.exe', false) then
- begin
- if MsgBox('安装程序检测到软件正在运行!'#13''#13'点击 "是" 按钮将关闭进程再继续安装;'#13''#13'点击"否" 按钮将退出安装!', mbConfirmation, MB_YESNO) = IDYES then
- KillTask('rhino.exe');
- Result:= true;
- end else begin
- Result:= false;//安装程序退出
- Exit;
- end;
- end;
- end;
- // 卸载时判断xxx是否正在运行
- function InitializeUninstall(): Boolean;
- var
- IsRunning: boolean;
- begin
- Result :=true; //卸载程序继续
- IsRunning:= IsAppRunning('rhino.exe');
- while IsRunning do
- begin
- if Msgbox('卸载检测到 软件 正在运行。' #13#13 '先关闭进程然后单击“确定”继续卸载,否则按“取消”退出卸载!', mbConfirmation, MB_OKCANCEL) = IDOK then
- begin
- IsRunning:= IsAppRunning('rhino.exe');
- Result :=true; //卸载程序继续
- end else begin
- IsRunning:= false;
- Result :=false; //卸载程序退出
- Exit;
- end;
- end;
- UnloadDLL(ExpandConstant('{app}\psvince.dll'));
- end;
复制代码 |
|