同意楼上,也可以
BOOL CreateProcess(    LPCTSTR lpApplicationName, // pointer to name of executable module 
    LPTSTR lpCommandLine, // pointer to command line string
    LPSECURITY_ATTRIBUTES lpProcessAttributes, // pointer to process security attributes 
    LPSECURITY_ATTRIBUTES lpThreadAttributes, // pointer to thread security attributes 
    BOOL bInheritHandles, // handle inheritance flag 
    DWORD dwCreationFlags, // creation flags 
    LPVOID lpEnvironment, // pointer to new environment block 
    LPCTSTR lpCurrentDirectory, // pointer to current directory name 
    LPSTARTUPINFO lpStartupInfo, // pointer to STARTUPINFO 
    LPPROCESS_INFORMATION lpProcessInformation  // pointer to PROCESS_INFORMATION  
   );

解决方案 »

  1.   

    计时简单,只要加一个Timer,只要程序一运行,就将Timer的Enable设为
    True,就行了(别忘了设时间)
      

  2.   

    用openprocess,terminateprocess函数就可以/111,必须还的知道processid是多少?
      

  3.   

    以下一个过程调用应用程序时会严重影响运行程序的效率,应该怎么办?
    procedure ExecAndWait(const Filename, Params: string; WindowState: word; TimeLimit:double;var usetime:double);
      { 执行一个程序,并在timelimit内结束它 , 返回其运行时间}
      { filename 执行文件名     params 参数      windowstate 显示方式,通常SW_SHOWMINIMIZED
        timelimit 时间限制     usetiem 返回程序运行的时间}
      { 注意要 uses   WinTypes, WinProcs, StdCtrls; }
    var
      SUInfo: TStartupInfo;
      ProcInfo: TProcessInformation;
      CmdLine: string;
      dwProc : THandle;
      starttime:Tdatetime;
    begin
      {得到命令行}
      { Enclose filename in quotes to take care of long filenames with spaces. }
      CmdLine := '"' + Filename + '"' + Params;  {得到SUINfo}
      FillChar(SUInfo, SizeOf(SUInfo), #0);
      with SUInfo do
      begin
        cb := SizeOf(SUInfo);
        dwFlags := STARTF_USESHOWWINDOW;
        wShowWindow := WindowState;
      end;  {建立一个进程}
      CreateProcess(NIL, PChar(CmdLine), NIL, NIL, FALSE,
      CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, NIL,
      PChar(ExtractFilePath(Filename)), SUInfo, ProcInfo);  { 执行并终止它 }
      Starttime := now;
      repeat
        dwProc:=OpenProcess(PROCESS_ALL_ACCESS or PROCESS_TERMINATE,FALSE,dword(ProcInfo.dwProcessId));
        sleep(50);
      until ((now - starttime)*24*60*60>timelimit) or (dwProc = 0);  usetime := (now-starttime)*24*60*60;  {终止程序}
      dwProc:=OpenProcess(PROCESS_ALL_ACCESS or PROCESS_TERMINATE,FALSE,dword(ProcInfo.dwProcessId));
      terminateprocess(dwProc,0);  { Clean up the handles. }
      CloseHandle(ProcInfo.hProcess);
      CloseHandle(ProcInfo.hThread);
    end;