杉宫竹苑工作室

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

Inno Setup 卸载时停用进程或服务代码

[复制链接]
发表于 2017-3-6 18:16:34 | 显示全部楼层 |阅读模式

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

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

x
卸载的时候,先判断这两个程序有没在运行,如果有运行就自动杀掉再卸载。
  1. function InitializeUninstall(): Boolean;
  2. var
  3.   IsAppRunning: boolean;
  4.   ResultCode: Integer;
  5. begin
  6.   Result:= true;
  7.   IsAppRunning:= IsModuleLoaded('AlarmRelay.exe');
  8.   while IsAppRunning do
  9.     begin
  10.       if MsgBox('检测到AlarmRelay正在运行,卸载时请关闭!'#13'要自动关闭它并继续吗?', mbConfirmation, MB_OKCANCEL) = IDOK then
  11.         begin
  12.           Exec(ExpandConstant('{app}\janhkill.exe'), 'AlarmRelay.exe', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
  13.           IsAppRunning:= IsModuleLoaded('AlarmRelay.exe');
  14.         end
  15.       else
  16.         begin
  17.           IsAppRunning:= false;
  18.           Result:= false;
  19.         end;
  20.     end;
  21.   if Result = true then
  22.     begin
  23.       IsAppRunning:= IsModuleLoaded('syncTime.exe');
  24.       while IsAppRunning do
  25.         begin
  26.           if MsgBox('检测到syncTime正在运行,卸载时请关闭!'#13'要自动关闭它并继续吗?', mbConfirmation, MB_OKCANCEL) = IDOK then
  27.             begin
  28.               Exec(ExpandConstant('{app}\janhkill.exe'), 'syncTime.exe', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
  29.               IsAppRunning:= IsModuleLoaded('syncTime.exe');
  30.             end
  31.           else
  32.             begin
  33.               IsAppRunning:= false;
  34.               Result:= false;
  35.             end;
  36.         end;
  37.     end;
  38. //  UnloadDLL(ExpandConstant('{app}\psvince.dll'));
  39. end;
复制代码

用插件 psvince.dll 是可以识别的。注意:如果你是用的 Unicode 版,要用 AnsiString 类型,即:
function IsModuleLoaded(modulename: AnsiString): Boolean;
external 'IsModuleLoaded@{app}\psvince.dll stdcall uninstallonly';

而那个进程 syncTime.exe 并不是表示 syncTime.exe 这文件在运行,所以你也就不能用 janhkill.exe 杀掉它。其实它是一个由  syncTime.exe 安装的系统服务,你只要停止这个服务就行了,也就是说你不要用
Exec(ExpandConstant('{app}\janhkill.exe'), 'syncTime.exe', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
而要用
Exec('net.exe', 'stop syncTimeSrv', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
  1. function InitializeUninstall(): Boolean;
  2. var
  3.   IsAppRunning: boolean;
  4.   ResultCode: Integer;
  5. begin
  6.   Result:= true;
  7.   IsAppRunning:= IsModuleLoaded('AlarmRelay.exe');
  8.   while IsAppRunning do
  9.     begin
  10.       if MsgBox('检测到AlarmRelay正在运行,卸载时请关闭!'#13'要自动关闭它并继续吗?', mbConfirmation, MB_OKCANCEL) = IDOK then
  11.         begin
  12.           Exec(ExpandConstant('{app}\janhkill.exe'), 'AlarmRelay.exe', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
  13.           IsAppRunning:= IsModuleLoaded('AlarmRelay.exe');
  14.         end
  15.       else
  16.         begin
  17.           IsAppRunning:= false;
  18.           Result:= false;
  19.         end;
  20.     end;
  21.   if Result = true then
  22.     begin
  23.        IsAppRunning:= IsModuleLoaded('syncTime.exe');
  24.       while IsAppRunning do
  25.         begin
  26.           if MsgBox('检测到syncTime正在运行,卸载时请关闭!'#13'要自动关闭它并继续吗?', mbConfirmation, MB_OKCANCEL) = IDOK then
  27.             begin
  28.               Exec('net.exe', 'stop syncTimeSrv', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
  29.               //Exec(ExpandConstant('{app}\janhkill.exe'), 'syncTime.exe', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
  30.               IsAppRunning:= IsModuleLoaded('syncTime.exe');
  31.             end
  32.           else
  33.             begin
  34.               IsAppRunning:= false;
  35.               Result:= false;
  36.             end;
  37.         end;
复制代码
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-19 20:10 , Processed in 0.109573 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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