InnoSetup 安装和卸载时判断程序是否运行的正确方式

网上找了看了很多类似文章,语法都不完整,第一次用[delphi] 的小伙伴们可以看下,注意替换自己需要检查的文件名,我的是

MyProg.exe
当然还有弹窗语句自己DIY咯!

[Code]
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 InitializeSetup(): Boolean;
begin
 Result := IsAppRunning('MyProg.exe');
  if Result then
  begin
      MsgBox('HJEBID正在运行,请先关闭程序后再重试! ', mbError, MB_OK); 
    result:=false;
end
else
    begin
      result := true;
    end;
  end;


你可能感兴趣的:(InnoSetup,InnoSetup)