我要在一个delphi中调用另外的exe程序,请问如何实现,给程序语句,谢谢了

解决方案 »

  1.   

    WinExec(...)
    CreateProcess(...)uses
      ShellAPI;ShellExecute(...)
      

  2.   

    WinExec
    ShellExecute
    有分我就接!!:)
      

  3.   

    WinExec
    ShellExecute
    microsoft建议用后一个!
      

  4.   

    function ExecFile(s:string): Integer;
    var
      ShellExecInfo: TShellExecuteInfo;
    begin
      if s<> '' then
      begin
        ZeroMemory(@ShellExecInfo, SizeOf(TShellExecuteInfo));    with ShellExecInfo do
        begin
          cbSize := SizeOf(TShellExecuteInfo);
          Wnd := Application.Handle;
          lpFile := PChar(s);
          ShellExecInfo.lpDirectory:=pchar(ExtractFilePath(s));
          nShow:=SW_SHOW;
        end;
      ShellExecuteEx(@ShellExecInfo);
     end;
    result:=0;
    end;
      

  5.   

    CreateProcess调用
    function runprocbycmd(cmd:string):integer;
    var
    sInfo : TStartupInfo;
    pInfo : TProcessInformation;
    exitCode : Cardinal; 
    begin
    SetCurrentDir(getworkpath);
    try
    FillChar(sInfo,sizeof(sInfo),#0);
    sInfo.cb := SizeOf(sInfo);
    sInfo.dwFlags := STARTF_USESHOWWINDOW;
    sInfo.wShowWindow := SW_NORMAL;if not CreateProcess(nil,pchar(cmd),nil,nil,false,CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil, nil, sInfo, pInfo) then
    MessageBox(Application.handle,pchar(srunprocfalse),pchar(serror),MB_OK or MB_ICONSTOP)
    else
    begin
    WaitForSingleObject(pInfo.hProcess,INFINITE);
    GetExitCodeProcess(pInfo.hProcess,exitCode);
    end;
    finally
    result:=exitCode;
    end;
    end;
      

  6.   

    WinExec,但是用Pchar不太安全。
      

  7.   

    VAR AEXE : STRING
    BEGIN
      AEXE := 'C:\KK.EXE';
    Winexec(Pchar(AEXE),SW_NORMAL)
    END;
      

  8.   

    加入shellapi单元,用下面两上函数
    WinExec
    ShellExecute
      

  9.   

    WinExec肯定可以, ShellExecute有时不行, 也不知道为什么?
      

  10.   

    WinExec('notepad.exe',1);
    ShellExecute(GetDesktopWindow(), NIl, 'rundll32.exe','shell32.dll,Control_RunDLL timeDate.cpl', Nil, 0);
    建议用后一种,它除了可以调用EXE外,还可以调用别的程序,比如说文本
      

  11.   

    var ExeFile:String;
    begin
       ExeFile:='执行程序名'   //含绝对路径
       If FileExists(ExeFile) then
         WinExec(Pchar(ExeFile),SW_SHOWNORMA)
       Else ShowMessage(ExeFile+' 不存在!');
    end;
      

  12.   

    http://community.csdn.net/Expert/topic/3380/3380241.xml?temp=.2008783先搜索下以前的帖子吧。