怎样开、关进程!请给出简单的代码!谢谢!

解决方案 »

  1.   

    var
      sa:SECURITY_ATTRIBUTES;
      hRead,hWrite:THandle;
      si:STARTUPINFO;
      pi:PROCESS_INFORMATION;
      bytesRead:DWORD;
      buffer:PChar;
    begin
      sa.nLength := sizeof(SECURITY_ATTRIBUTES);
      sa.lpSecurityDescriptor := Nil;
      sa.bInheritHandle := TRUE;
      
      si.cb := sizeof(STARTUPINFO);
      GetStartupInfo(si);
      si.hStdError := hWrite;
      si.hStdOutput := hWrite;
      si.wShowWindow := SW_HIDE;
      si.dwFlags := STARTF_USESHOWWINDOW;
      if ( not CreateProcess(nil,PChar('d:\\winnt\\system32\\cmd.exe')
            ,nil,nil,true,0,nil,nil,si,pi)) then
      begin
        ShowMessage('Error on CreateProcess()');
        exit;
      end;
    end;这段代码创建进程,终止进程用TerminateProcess 
      

  2.   

    var
      sa: SECURITY_ATTRIBUTES;
      hRead, hWrite: THandle;
      si: STARTUPINFO;
      pi: PROCESS_INFORMATION;
      bytesRead: DWORD;
      buffer: PChar;
    begin
      sa.nLength := sizeof(SECURITY_ATTRIBUTES);
      sa.lpSecurityDescriptor := nil;
      sa.bInheritHandle := TRUE;  si.cb := sizeof(STARTUPINFO);
      GetStartupInfo(si);
      si.hStdError := hWrite;
      si.hStdOutput := hWrite;
      si.wShowWindow := SW_SHOW;
      si.dwFlags := STARTF_USESHOWWINDOW;
      if ( not CreateProcess(nil,PChar('d:\\winnt\\system32\\cmd.exe')
            ,nil,nil,true,0,nil,nil,si,pi)) then
      begin
        ShowMessage('Error on CreateProcess()');
        exit;
      end;  TerminateProcess(pi.hProcess,0);end;
      

  3.   

    看第二贴给出TerminateProcess用法
      

  4.   

    1.开:winexec
    2.关:
    //检查XCOPY是否完毕
    var
      hSnapshot:integer;
      bFound:BOOL;
      processentry:PROCESSENTRY32;
    begin
       hSnapshot:=CreateToolHelp32SnapShot(TH32cs_snapprocess,0);
       if hSnapshot=0 then
            exit;
         bFound:=process32first(hSnapshot,ProcessEntry);
         while bFound do
             begin
                if (LowerCase(ProcessEntry.szexeFile)='qq.exe') then
                  begin
                    hprocess:=OpenProcess(Process_all_access,false,processEntry.th32ProcessID);
                   if hprocess<>0 then
                      TerminateProcess(Hprocess,0);
                  end;
                  bFound:=process32next(hSnapshot,processentry);
             end;
          CloseHandle(hSnapshot);
    end;