各位高手:怎样在Delphi中调用exe程序?
如:用delphi作了一个exe程序,怎样在另外一个窗体中的调用这个exe程序?谢谢!
我会尽快结帖!

解决方案 »

  1.   

    uses ShellApi;
    ...
    ShellExecute(self.Handle, 'open', 'd:\pro.exe',  nil, nil, SW_SHOWNORMAL);
    WinExec('d:\pro.exe', SW_SHOWNORMAL);
      

  2.   

    const
      cmdLine := 'c:\windows\notepad.exe';
    var
      sInfo : TStartupInfo;
      pInfo : TProcessInformation;
    begin
      FillChar(sInfo,sizeof(sInfo),#0);
      sInfo.cb := SizeOf(sInfo);
      sInfo.dwFlags := STARTF_USESHOWWINDOW;
      sInfo.wShowWindow := SW_NORMAL;  if not CreateProcess(nil,pchar(cmdLine),nil,nil,false,CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil, nil, sInfo, pInfo) then
        MessageBox(Application.handle,'指定程序启动失败!','错误',MB_OK or MB_ICONSTOP)
      else
      begin
        WaitForSingleObject(pInfo.hProcess,INFINITE);
        GetExitCodeProcess(pInfo.hProcess,exitCode);
      end;
    end;
      

  3.   

    uses ShellApi;
    ...
    ShellExecute(self.Handle, 'open', 'd:\pro.exe',  nil, nil, SW_SHOWNORMAL);
    WinExec('d:\pro.exe', SW_SHOWNORMAL);
      

  4.   

    procedure TForm1.Button1Click(Sender: TObject);
    var s: String;
    begin
        s:=ExtractFilePath(Application.ExeName)+'yourApp.exe';
        winExec(pchar(s),SW_SHOWNORMAL);
    end;
      

  5.   

    用CreateProcess()的意见,100分
    用ShellExecute()的意见,90分
    用WinExec()的意见,60分
      

  6.   

    用CreateProcess()的意见,100分
    用ShellExecute()的意见,90分
    用WinExec()的意见,60分
      

  7.   

    使用ShellExecute,具体用法如下
    ShellExecute(调用窗口的句柄,'open',被调用函数名,调用参数,被调用函数目录,SW_SHOW);
      

  8.   

    uses ShellApi;var
    svar:string;
    begin
    svar:='c:\name.exe';
    ...
    ShellExecute(self.Handle, 'open', svar,  nil, nil, SW_SHOWNORMAL);
      

  9.   

    关键字:
    WinExecShellExecute在CSDN搜索一大把
      

  10.   

    ShellExecutewinExecF1 Help a once.
    =====================================
      

  11.   

    还有:function WinExecAndWait(Path: string; Visibility: Word): DWORD; function CreateProcessAndWait(const AppPath, AppParams: string;
       Visibility: Word): DWORD;
     var
       SI: TStartupInfo;
       PI: TProcessInformation;
       Proc: THandle;
       WaitResult: DWORD;
     begin
       FillChar(SI, SizeOf(SI), 0);
       SI.cb := SizeOf(SI);
       SI.wShowWindow := Visibility;
       SI.dwFlags := STARTF_USESHOWWINDOW;
       if not CreateProcess(PChar(AppPath), PChar(AppParams), nil, nil, False,
         NORMAL_PRIORITY_CLASS, nil, nil, SI, PI) then
         raise Exception.CreateFmt('不能执行,请输入或选择可执行文件的名称和路径.错误信息为“%s”',
           [SysErrorMessage(GetLastError)]);
       Proc := PI.hProcess;
       CloseHandle(PI.hThread);
       repeat
         Application.ProcessMessages;
         WaitResult := WaitForSingleObject(Proc, 200);
       until (WaitResult <> WAIT_TIMEOUT) or (WaitResult = WAIT_FAILED);
       GetExitCodeProcess(Proc, Result);
       CloseHandle(Proc);
     end;var
     P: Integer;
     Params: string;
    begin
     Params := Path;
     P := Pos(' ', Path); // assume params start at first space
     Delete(Path, P, Length(Path));
     Result := CreateProcessAndWait(Path, Params, Visibility);
    end;  
      

  12.   

    Visibility应该是:Value  Meaning
    SW_HIDE  Hides the window and activates another window.
    SW_MAXIMIZE  Maximizes the specified window.
    SW_MINIMIZE  Minimizes the specified window and activates the next top-level window in the Z order.
    SW_RESTORE  Activates and displays the window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when restoring a minimized window.
    SW_SHOW  Activates the window and displays it in its current size and position. 
    SW_SHOWDEFAULT  Sets the show state based on the SW_ flag specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application. 
    SW_SHOWMAXIMIZED  Activates the window and displays it as a maximized window.
    SW_SHOWMINIMIZED  Activates the window and displays it as a minimized window.
    SW_SHOWMINNOACTIVE  Displays the window as a minimized window. The active window remains active.
    SW_SHOWNA  Displays the window in its current state. The active window remains active.
    SW_SHOWNOACTIVATE  Displays a window in its most recent size and position. The active window remains active.
    SW_SHOWNORMAL  Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when displaying the window for the first time.
      

  13.   

    明摆着送分,楼主我也来了,呵呵。
    uses ShellApi;ShellExecute
    WinExec