论坛风格切换切换到宽版
  • 4450阅读
  • 4回复

虎版,我这个卸载杀进程的代码能否帮我修改一下? [复制链接]

上一主题 下一主题
离线373723699
 

发帖
38
金钱
380
威望
38
只看楼主 倒序阅读 0 发表于: 2013-12-04
我的想再卸载的时候,先判断这两个程序有没在运行,如果有运行就自动杀掉再卸载。
我看了论坛以前发的帖子,也成功杀掉了,但是只有一个进程,我现在有2个进程,代码部分我不会修改,现在发上来帮忙看看,如何改?

function InitializeUninstall(): Boolean;
var
IsAppRunning: boolean;
IsAppRunning2: boolean;
ResultCode: Integer;
begin
begin
Result:= true;
IsAppRunning:= IsModuleLoaded('AlarmRelay.exe');
while IsAppRunning
do
begin
if MsgBox('检测到AlarmRelay正在运行,卸载时请关闭!'#13'要自动关闭它并继续吗?', mbConfirmation, MB_OKCANCEL) = IDOK then
begin
Exec(ExpandConstant('{app}\janhkill.exe'), 'AlarmRelay.exe', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
IsAppRunning:= IsModuleLoaded('AlarmRelay.exe');
end
else
begin
IsAppRunning:= false;
Result:= false;
end;
end;
UnloadDLL(ExpandConstant('{app}\psvince.dll'));
end;

begin
Result:= true;
IsAppRunning2:= IsModuleLoaded('syncTime.exe');
while IsAppRunning
do
begin
if MsgBox('检测到syncTime正在运行,卸载时请关闭!'#13'要自动关闭它并继续吗?', mbConfirmation, MB_OKCANCEL) = IDOK then
begin
Exec(ExpandConstant('{app}\janhkill.exe'), 'syncTime.exe', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
IsAppRunning:= IsModuleLoaded('syncTime.exe');
end
else
begin
IsAppRunning:= false;
Result:= false;
end;
end;
UnloadDLL(ExpandConstant('{app}\psvince.dll'));
end
end;

这个是我自己写的代码,但是还是只能检测第一个进程,插件什么的又需要我再上传。
离线gnatix

发帖
7696
金钱
-8279
威望
-828
只看该作者 1 发表于: 2013-12-04
不能测试,但是估计应该可以这样:

function InitializeUninstall(): Boolean;
var
  IsAppRunning: boolean;
  ResultCode: Integer;
begin
  Result:= true;
  IsAppRunning:= IsModuleLoaded('AlarmRelay.exe');
  while IsAppRunning do
    begin
      if MsgBox('检测到AlarmRelay正在运行,卸载时请关闭!'#13'要自动关闭它并继续吗?', mbConfirmation, MB_OKCANCEL) = IDOK then
        begin
          Exec(ExpandConstant('{app}\janhkill.exe'), 'AlarmRelay.exe', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
          IsAppRunning:= IsModuleLoaded('AlarmRelay.exe');
        end
      else
        begin
          IsAppRunning:= false;
          Result:= false;
        end;
    end;
  if Result = true then
    begin
      IsAppRunning:= IsModuleLoaded('syncTime.exe');
      while IsAppRunning do
        begin
          if MsgBox('检测到syncTime正在运行,卸载时请关闭!'#13'要自动关闭它并继续吗?', mbConfirmation, MB_OKCANCEL) = IDOK then
            begin
              Exec(ExpandConstant('{app}\janhkill.exe'), 'syncTime.exe', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
              IsAppRunning:= IsModuleLoaded('syncTime.exe');
            end
          else
            begin
              IsAppRunning:= false;
              Result:= false;
            end;
        end;
    end;
//  UnloadDLL(ExpandConstant('{app}\psvince.dll'));
end;
离线373723699

发帖
38
金钱
380
威望
38
只看该作者 2 发表于: 2013-12-05
回 1楼(gnatix) 的帖子
虎版,你这个代码连接的没有问题,但是我这个进程其中有个叫syncTime.exe文件的,进程可以看到,代码不能识别到,我不知道为什么,名字我确认很多次没错,唯一跟别的不同的是它是system的,这个应用是时间同步的一个软件,我用了好几种办法就是杀不掉。
打开syncTime.exe的方法是双击文件夹下的IAP TimeSync.bat批处理文件,进程里就会出现syncTime.exe的条目,手动可以删除。
我不知道什么原因,可否麻烦虎版帮我看下。我附件上传了我的源码demo和这个应用,还有插件,东西不多,麻烦你了。
(PS:东西绝对是绿色无毒安全的东西,打开后可以进程关掉)
测试.zip (274 K) 下载次数:3


离线gnatix

发帖
7696
金钱
-8279
威望
-828
只看该作者 3 发表于: 2013-12-06
用插件 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);


离线gnatix

发帖
7696
金钱
-8279
威望
-828
只看该作者 4 发表于: 2013-12-06

      IsAppRunning:= IsModuleLoaded('syncTime.exe');
      while IsAppRunning do
        begin
          if MsgBox('检测到syncTime正在运行,卸载时请关闭!'#13'要自动关闭它并继续吗?', mbConfirmation, MB_OKCANCEL) = IDOK then
            begin
              Exec('net.exe', 'stop syncTimeSrv', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
              //Exec(ExpandConstant('{app}\janhkill.exe'), 'syncTime.exe', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
              IsAppRunning:= IsModuleLoaded('syncTime.exe');
            end
          else
            begin
              IsAppRunning:= false;
              Result:= false;
            end;
        end;