Inno Setup Kill a running process

前端 未结 4 1030
时光取名叫无心
时光取名叫无心 2020-12-18 11:01

I have already implemented a way to find whether a process (\"iexplore.exe\") is running, I now need to find a way to close it (terminate the process) from Inno Setup.

4条回答
  •  一个人的身影
    2020-12-18 11:27

    Version with use of Win32_Process, you call the procedure with i.e. 'notepad.exe':

    const wbemFlagForwardOnly = $00000020;
    
    procedure CloseApp(AppName: String);
    var
      WbemLocator : Variant;
      WMIService   : Variant;
      WbemObjectSet: Variant;
      WbemObject   : Variant;
    begin;
      WbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
      WMIService := WbemLocator.ConnectServer('localhost', 'root\CIMV2');
      WbemObjectSet := WMIService.ExecQuery('SELECT * FROM Win32_Process Where Name="' + AppName + '"');
      if not VarIsNull(WbemObjectSet) and (WbemObjectSet.Count > 0) then
      begin
        WbemObject := WbemObjectSet.ItemIndex(0);
        if not VarIsNull(WbemObject) then
        begin
          WbemObject.Terminate();
          WbemObject := Unassigned;
        end;
      end;
    end;
    

提交回复
热议问题