innosetup 判断进程是否存在

//;判断进程是否存在
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;

//安装的时候判断进程是否存在
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}\FF\UserDataDefault')) then
        DelTree(ExpandConstant('{localappdata}\FF\UserDataDefault'), 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;  

 

posted @ 2021-11-05 14:20  冰糖葫芦很乖  阅读(382)  评论(0编辑  收藏  举报