InnoSetup判断应用程序是否正在运行的函数

将下面函数加入到[code]段,参数为应用程序的可执行文件名称,不带路径:


function IsAppRunning(const FileName : string): Boolean;
var
    FSWbemLocator: Variant;
    FWMIService   : 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;

调用方式如:

 if IsAppRunning('qdpayconsole.exe') then
  begin

  end;


你可能感兴趣的:(InnoSetup判断应用程序是否正在运行的函数)