杉宫竹苑工作室

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2387|回复: 0

Inno Setup 中 istask 插件检测安装或卸载程序关闭进程

[复制链接]
发表于 2017-1-9 16:28:51 | 显示全部楼层 |阅读模式

正式会员享受无限制浏览网站功能和高速网盘下载,赶快加入本站吧!

您需要 登录 才可以下载或查看,没有账号?立即注册

x

  1. [Files]; 安装前判断进程,dll文件放在inno的安装目录中
  2. Source: "compiler:ISTask.dll"; DestDir: "{tmp}"; Flags: deleteafterinstall dontcopy
  3. Source: "compiler:ISTask.dll"; DestDir: "{app}";
  4. Source: "compiler:psvince.dll"; DestDir: "{tmp}"; Flags: deleteafterinstall dontcopy
  5. Source: "compiler:psvince.dll"; DestDir: "{app}";


  6. [Code]
  7. //安装前判断是否有进程正在运行
  8. // PSVince控件无法检测到64位exe程序的进程,使用下面的函数可以解决。
  9. function IsAppRunning(const FileName: string): Boolean;
  10. var
  11.   FWMIService: Variant;
  12.   FSWbemLocator: Variant;
  13.   FWbemObjectSet: Variant;
  14. begin
  15.   Result := false;
  16.   FSWbemLocator := CreateOleObject('WBEMScripting.SWBEMLocator');
  17.   FWMIService := FSWbemLocator.ConnectServer('', 'root\CIMV2', '', '');
  18.   FWbemObjectSet := FWMIService.ExecQuery(Format('SELECT Name FROM Win32_Process Where Name="%s"',[FileName]));
  19.   Result := (FWbemObjectSet.Count > 0);
  20.   FWbemObjectSet := Unassigned;
  21.   FWMIService := Unassigned;
  22.   FSWbemLocator := Unassigned;
  23. end;

  24. function RunTask(FileName: string; bFullpath: Boolean): Boolean;
  25.    external 'RunTask@files:ISTask.dll stdcall delayload';

  26. function KillTask(ExeFileName: string): Integer;
  27.    external 'KillTask@files:ISTask.dll stdcall delayload';
  28.    
  29. function InitializeSetup():boolean;
  30. var
  31.    IsRunning: boolean;
  32. // 第二步,安装时判断客户端是否正在运行,注意:使用IsAppRunning函数(已在前面定义),
  33.     //可以在32和64位系统下检测32和64位进程,但还是不能识别进程的版本,如果有多版本的话。
  34.     begin
  35.       Result:= true;//安装程序继续
  36.        if not RegKeyExists(HKEY_LOCAL_MACHINE, 'SOFTWARE\McNeel\Rhinoceros\5.0x64') then
  37.        begin
  38.          MsgBox('该系统未检测软件程序,请先行安装软件程序!', mbInformation, MB_OK);
  39.          Result := False;
  40.        end;
  41.       IsRunning:= IsAppRunning('rhino.exe');
  42.       while IsRunning do
  43.          begin
  44.            if MsgBox('安装检测到 软件 正在运行!' #13#13 '先关闭所有软件之后,再单击“确定”继续安装,否则按“取消”退出安装!', mbConfirmation, MB_OKCANCEL) = IDOK then
  45.              begin
  46.              IsRunning:= IsAppRunning('rhino.exe');
  47.              Result:= true;
  48.              end else begin
  49.              IsRunning:= false;
  50.              Result:= false;//安装程序退出
  51.              Exit;
  52.              end;
  53.          end;
  54.     end;
  55.      


  56.     begin
  57.       Result:= true;//安装程序继续
  58.          if RunTask('rhino.exe', false) then
  59.          begin
  60.            if MsgBox('安装程序检测到软件正在运行!'#13''#13'点击 "是" 按钮将关闭进程再继续安装;'#13''#13'点击"否" 按钮将退出安装!', mbConfirmation, MB_YESNO) = IDYES then
  61.               KillTask('rhino.exe');
  62.               Result:= true;
  63.               end else begin
  64.               Result:= false;//安装程序退出
  65.               Exit;
  66.          end;
  67.     end;
  68. end;

  69. // 卸载时判断xxx是否正在运行

  70. function InitializeUninstall(): Boolean;
  71. var
  72.   IsRunning: boolean;
  73. begin
  74.   Result :=true;  //卸载程序继续
  75.   IsRunning:= IsAppRunning('rhino.exe');
  76.   while IsRunning do
  77.   begin
  78.     if Msgbox('卸载检测到 软件 正在运行。'  #13#13 '先关闭进程然后单击“确定”继续卸载,否则按“取消”退出卸载!', mbConfirmation, MB_OKCANCEL) = IDOK then
  79.     begin
  80.       IsRunning:= IsAppRunning('rhino.exe');
  81.       Result :=true; //卸载程序继续
  82.     end else begin
  83.       IsRunning:= false;
  84.       Result :=false; //卸载程序退出
  85.       Exit;
  86.     end;
  87.   end;
  88.   UnloadDLL(ExpandConstant('{app}\psvince.dll'));
  89. end;
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SgzyStudio

GMT+8, 2024-5-8 08:55 , Processed in 0.122403 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表