执行  winexec('arj32 -a 源地址 目的地址’,SW_HIDE)时,产生ARJ32进程,请问如何在delphi 下关闭

解决方案 »

  1.   

    1.用CreateToolhelp32Snapshot或EnumProcesses枚举系统进程,得到arj32进程的handle,然后用TerminateProcess终止进程
    2.最简的方法,不用winexec而改用CreateProcess调用arj32,这样可直接得到arj32进程的handle
    ,然后用TerminateProcess终止进程
      

  2.   

    楼下的抄了两个例子 :-)
    ------------------------------------------------------------------------------------
    // uses Windows, SysUtils
    procedure ProgramRunWait(const CommandLine,DefaultDirectory: string;Wait: boolean);
    var
      StartUpInfo: TStartUpInfo;
      ProcInfo: Process_Information;
      Dir, Msg: PChar;
      ErrNo: integer;
      E: Exception;
    begin
      FillChar(StartUpInfo, SizeOf(StartUpInfo), 0);
      StartUpInfo.cb := SizeOf(StartUpInfo);
      if DefaultDirectory <> '' then
        Dir := PChar(DefaultDirectory)
      else
        Dir := nil;
      if CreateProcess(nil,
                       PChar(CommandLine),
                       nil,
                       nil,
                       False,
                       0,
                       nil,
                       Dir,
                       StartUpInfo,
                       ProcInfo) then
      begin
        try
          if Wait then
            WaitForSingleObject(ProcInfo.hProcess,
                                INFINITE);
        finally
          CloseHandle(ProcInfo.hThread);
          CloseHandle(ProcInfo.hProcess);
        end;
      end
      else
      begin
        ErrNo := GetLastError;
        Msg := AllocMem(4096);
        try
          FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
                        nil,
                        ErrNo,
                        0,
                        Msg,
                        4096,
                        nil);
          E := Exception.Create('Create Process Error #'
                                + IntToStr(ErrNo)
                                + ': '
                                + string(Msg));
        finally
          FreeMem(Msg);
        end;
        raise E;
      end;
    end;-----------------------------------------------------------------------------
    var
     x : STARTUPINFO;
     y : PROCESS_INFORMATION;
     j : Longbool;
     z : DWORD;
     b : array[1..100] of char;
     s : string;
    begin
      x.cb          := sizeof(x);
      x.lpReserved  := nil ;   //required
      x.lpDesktop   := nil ;   //required
      x.lpTitle     := nil ;   //required
      x.dwFlags     := STARTF_USESHOWWINDOW ;
      x.wShowWindow := SW_SHOW;
      x.cbReserved2 := 0 ;    // required
      x.lpReserved2 := nil;
        // lpCommandLine finds the application in the current path
      j := CreateProcess(nil, 'notepad.exe', nil, nil,
         false, CREATE_NEW_CONSOLE + NORMAL_PRIORITY_CLASS, nil, 'c:', x, y);  if j=false then begin
        z := GetLastError() ;
        FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,nil,z,0,@b, 99, nil);
        s := b;
        ShowMessage(s);
      end;
    end;    // With lpApplicationName, the full path must be specified
      j := CreateProcess('c:\windows\notepad.exe', '', nil, nil,
         false, CREATE_NEW_CONSOLE + NORMAL_PRIORITY_CLASS, nil, 'c:\', x, y);--
    http://www.agui.googlepages.com
    mailto: agui.cn(a)gmail.com
      

  3.   

    简单问题
    直接Baidu,Google啦
      

  4.   


    下面是我从网上找到的方法,很好用,目前已解决谢谢大家
    procedure Tdmpublic.KillProc(procname: string);//程序名为变量
    const
      PROCESS_TERMINATE=$0001;
    var
      ExeFileName: String;
      ContinueLoop: BOOL;
      FSnapshotHandle: THandle;
      FProcessEntry32: TProcessEntry32;
    begin
      ExeFileName := procname;
      FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
      FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
      ContinueLoop := Process32First(FSnapshotHandle,FProcessEntry32);
      while integer(ContinueLoop) <> 0 do
        begin
          if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =
               UpperCase(ExeFileName))
           or (UpperCase(FProcessEntry32.szExeFile) =
               UpperCase(ExeFileName))) then
            TerminateProcess(OpenProcess(PROCESS_TERMINATE, BOOL(0),
                              FProcessEntry32.th32ProcessID), 0);
          ContinueLoop := Process32Next(FSnapshotHandle,FProcessEntry32);
        end;
    end;