论坛风格切换切换到宽版
  • 6894阅读
  • 12回复

【已解决】套用网上的卸载判断代码为什么不起作用 [复制链接]

上一主题 下一主题
离线solan
 

发帖
80
金钱
800
威望
80
只看楼主 正序阅读 0 发表于: 2015-11-06
如下代码为什么不起作用,请好心人在百忙之中帮我解答一下不甚感激
  1. // 卸载时判断程序是否正在运行
  2. function InitializeUninstall(): Boolean;
  3. var
  4.   IsRunning: Integer;
  5. begin  
  6.   Result :=true;  //卸载程序继续  
  7.       IsRunning:=FindWindowByWindowName('KL 8.5_32bit -');
  8.       IsRunning:=FindWindowByWindowName(KL 8.5_64bit -');  
  9.   while IsRunning<>0 do  
  10.   begin  
  11.     if Msgbox('安装程序检测到KL8.5正在运行。'  #13#13 '您必须先关闭它然后单击“是”继续卸载,或则按“否”退出!', mbConfirmation, MB_YESNO) = idNO then  
  12.     begin  
  13.       Result :=false; //安装程序退出  
  14.       IsRunning :=0;  
  15.     end else begin  
  16.       Result :=true;  //安装程序继续  
  17.       IsRunning:=FindWindowByWindowName('KL 8.5_32bit -');
  18.       IsRunning:=FindWindowByWindowName('KL 8.5_64bit -');
  19.     end;  
  20.   end;  
  21. end;



离线solan

发帖
80
金钱
800
威望
80
只看该作者 12 发表于: 2015-12-15
离线solan

发帖
80
金钱
800
威望
80
只看该作者 11 发表于: 2015-11-22
  1. function InitializeSetup():boolean;
  2. var
  3.   ResultCode: Integer;
  4.   IsRunning: Integer;
  5. begin
  6. Result :=true;  //安装程序继续
  7.   Exec(ExpandConstant('{cmd}'), 'for /f %%i ' +
  8.          'in (''reg query "HKCU\Software\KL\Running Applications"^|findstr /i /r /c:"^ *KL V26\.5 [0-9][0-9]*"^|find /c /v ""'') ' +
  9.          'do set IsRunning=%%i'
  10.          ,ExpandConstant('{app}'), SW_SHOWNORMAL, ewNoWait, ResultCode);
  11.   while IsRunning<>0 do
  12.   begin
  13.     if Msgbox('安装程序检测到KL8.5正在运行。'  #13#13 '您必须先关闭它然后单击“是”继续安装,或则按“否”退出!', mbConfirmation, MB_YESNO) = idNO then
  14.     begin
  15.       Result :=false; //安装程序退出
  16.       IsRunning :=0;
  17.     end else
  18.     begin
  19.         Exec(ExpandConstant('{cmd}'), 'for /f %%i ' +
  20.          'in (''reg query "HKCU\Software\KL\Running Applications"^|findstr /i /r /c:"^ *KL V26\.5 [0-9][0-9]*"^|find /c /v ""'') ' +
  21.          'do set IsRunning=%%i'
  22.          ,ExpandConstant('{app}'), SW_SHOWNORMAL, ewNoWait, ResultCode);
  23.     end;
  24.   end;
  25. end;
  26. end;
  27. function InitializeUninstall(): Boolean;
  28. var
  29.   IsRunning: Integer;
  30. begin
  31.   Result :=true;  //卸载程序继续
  32.   Exec(ExpandConstant('{cmd}'), 'for /f %%i ' +
  33.          'in (''reg query "HKCU\Software\KL\Running Applications"^|findstr /i /r /c:"^ *KL V26\.5 [0-9][0-9]*"^|find /c /v ""'') ' +
  34.          'do set IsRunning=%%i'
  35.          ,ExpandConstant('{app}'), SW_SHOWNORMAL, ewNoWait, ResultCode);
  36.   while IsRunning<>0 do
  37.   begin
  38.     if Msgbox('安装程序检测到KL8.5正在运行。'  #13#13 '您必须先关闭它然后单击“是”继续卸载,或则按“否”退出!', mbConfirmation, MB_YESNO) = idNO then
  39.     begin
  40.       Result :=false; //卸载程序退出
  41.       IsRunning :=0;
  42.     end else
  43.     begin
  44.        Exec(ExpandConstant('{cmd}'), 'for /f %%i ' +
  45.          'in (''reg query "HKCU\Software\KL\Running Applications"^|findstr /i /r /c:"^ *KL V26\.5 [0-9][0-9]*"^|find /c /v ""'') ' +
  46.          'do set IsRunning=%%i'
  47.          ,ExpandConstant('{app}'), SW_SHOWNORMAL, ewNoWait, ResultCode);
  48.     end;
  49.   end;
  50. end;



我瞎搞了一阵,但是运行上面代码,出现报警



离线solan

发帖
80
金钱
800
威望
80
只看该作者 10 发表于: 2015-11-22
请问1楼的代码该怎么改
离线solan

发帖
80
金钱
800
威望
80
只看该作者 9 发表于: 2015-11-22
是插入批处理代码,不是执行批处理文件哦
离线solan

发帖
80
金钱
800
威望
80
只看该作者 8 发表于: 2015-11-22
  1. @echo off
  2. for /f %%i in ('reg query "HKCU\Software\KL\Running Applications"^|findstr /i /r /c:"^ *KL V26\.5 [0-9][0-9]*"^|find /c /v ""')do (
  3.     echo 有 %%i 个程序在运行
  4. )
  5. pause

我讨教了批处理高手,根据6楼的信息,得到这个批处理,可以判断程序是否在运行。
那么问题来了,在inno里面怎么插入批处理代码呢,当然代码要改一下。我这个一窍不懂,
请版主帮忙。

离线solan

发帖
80
金钱
800
威望
80
只看该作者 7 发表于: 2015-11-17
经过版主的指点,我的安装包就只差判断有无运行这个功能了,其他的基本上差不多了
离线solan

发帖
80
金钱
800
威望
80
只看该作者 6 发表于: 2015-11-09
我提供一下线索,这个软件运行时会在HKEY_CURRENT_USER\Software\KL\Running Applications下面即时产生有规律的键值,比如:
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\KL\Running Applications]
"KL V28.0 1"=dword:0000d7bc
"KL V28.0 2"=dword:0000f485
"KL V26.5 1"=dword:0000f4aa
"KL V26.5 2"=dword:0000f50f

姑且叫这个软件为KL吧,那么KL8.5版本运行时产生KL V26.5,KL10.0运行时产生V28.0
上面的注册表文件表示同时打开了2个KL8.5和2个KL10.0,后面会加上序号1、2、3、4。。。。
那么根据这些信息能不能用来判断安装和卸载时有没有KL在运行呢?
比如我现在想用inno打包KL8.5,那我怎么判断KL8.5有没有在运行呢?
请版主白忙之中帮一下忙,谢谢
离线solan

发帖
80
金钱
800
威望
80
只看该作者 5 发表于: 2015-11-09
正如版主所言,那个窗口名会随时改变的,所以上面的代码起不了作用,请版主开恩,我该怎么办
离线solan

发帖
80
金钱
800
威望
80
只看该作者 4 发表于: 2015-11-07
好的,我先试试,多谢