innosetup 判断进程是否存在

//;判断进程是否存在
function IsAppRunning(const FileName : string): Boolean;
var
    FSWbemLocator: Variant;
    FWMIService   : Variant;
    FWbemObjectSet: Variant;
begin
    Result := false;
    FSWbemLocator := CreateOleObject('WBEMScripting.SWBEMLocator');
    FWMIService := FSWbemLocator.ConnectServer('', 'rootCIMV2', '', '');
    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('{#MyAppExeName}');
  if Result then
  begin
      MsgBox('程序正在运行,请先关闭程序后再重试! ', mbError, MB_OK); 
    result:=false;
  end
  else
    begin
      result := true;
      if FileOrDirExists(ExpandConstant('{localappdata}FeikuaBrowserUserDataDefault')) then
        DelTree(ExpandConstant('{localappdata}FeikuaBrowserUserDataDefault'), True, True, True);
    end;
end;


//卸载的时候判断进程是否存在
function InitializeUninstall(): Boolean;
begin
 Result := IsAppRunning('{#MyAppExeName}');
  if Result then
  begin
      MsgBox('程序正在运行,请先关闭程序后再重试! ', mbError, MB_OK); 
    result:=false;
  end
else
    begin
      result := true;
    end;
end;  
原文地址:https://www.cnblogs.com/Galesaur-wcy/p/15513086.html