小弟在写程序时突然想到的一个问题!!!
就是如何在运行一个程序时能通过该程序调用其它应用程序!

解决方案 »

  1.   

    //执行ipconfig /all 输出到c:\aa.txt
     winexec(pchar('command.com /c ipconfig /all >c:\aa.txt'),sw_hide);其它类似
      

  2.   

    createprocess(...)
    ShellExecute(...)
    后者比较简单,比如
    ShellExecute(Handle,'open',‘c:\windows\notepad.exe',PChar'c:\a.txt',nil,SW_SHOWNORMAL);
      

  3.   

    贴的有问题……
    ShellExecute(Handle,'open',‘c:\windows\notepad.exe','c:\a.txt',nil,SW_SHOWNORMAL);
      

  4.   

    function RunProgram(ProgramName:string;Wait:Boolean=False):Cardinal;
    var
      StartInfo:STARTUPINFO;
      ProcessInfo:PROCESS_INFORMATION;
    begin
    //执行外部程序,失败返回0,成功返回进程句柄
      Result:=0;
      if ProgramName='' then exit;
      GetStartupInfo(StartInfo);
      StartInfo.dwFlags:=StartInfo.dwFlags or STARTF_FORCEONFEEDBACK;
      if not CreateProcess(nil,PChar(ProgramName),nil,nil,false,0,
              nil,nil,StartInfo,ProcessInfo) then  exit;
      Result:=ProcessInfo.hProcess;
      //建立进程成功
      //如果异步执行则退出
      if not wait then exit;
      while IsProgram_Runing(Result) do Application.ProcessMessages;
    end;
    function IsProgram_Runing(hProcess:Cardinal):Boolean;
    var
      ExitCode:Cardinal;
    begin
      //查看进程是否正在运行
      GetExitCodeProcess(hProcess,ExitCode);
      if ExitCode=STILL_ACTIVE then
        Result:=True
      else
        Result:=False;
    end;
      

  5.   

    是API函数!!不好意思,我还是第一次用.谢了!!!
      

  6.   

    RunProgram('c:\windows\notepad.exe c:\aa.txt',false);
      

  7.   

    RunProgram函数有一个特点,如果Wait参数设为真的话,你可以等待程序运行完毕,再进行下一步的工作。
    如果Wait参数设为假的话,和ShellExecute,winexec效果一样。
      

  8.   

    ShellExecute(handle, 'open', pchar('ping.exe'), '127.0.0.1 -t', nil,sw_shownormal); // ShellExecute in unit ShellAPI
      
      Winexec(pchar('Ping 127.0.0.1 -t'), SW_SHOW); // WinExec in unit Windows
      

  9.   

    ShellExecute(handle, 'open', pchar('ping.exe'), '127.0.0.1 -t', nil,sw_shownormal); // ShellExecute in unit ShellAPI
      
      Winexec(pchar('Ping 127.0.0.1 -t'), SW_SHOW); // WinExec in unit Windows
      

  10.   

    ShellExecute(handle, 'open', pchar('ping.exe'), '127.0.0.1 -t', nil,sw_shownormal); // ShellExecute in unit ShellAPI
      
      Winexec(pchar('Ping 127.0.0.1 -t'), SW_SHOW); // WinExec in unit Windows