不行吧!shellexecute执行的是任何文件执行的外挂程序!而不是执行某个环境下的命令!

解决方案 »

  1.   

    //这是一个同步执行命令行的函数;function TForm1.ExecuteAndWait(const CommandLine : string) : cardinal;
    var
     tSI : TStartupInfo;
     tPI : TProcessInformation;
     dwI : DWORD;
     VarU : UINT;
    begin
     Result := 0;
     FillChar(tSI, sizeof(TStartupInfo), 0);
     tSI.cb := sizeof(TStartupInfo); if (CreateProcess(nil, pchar(CommandLine), nil, nil, False, 0, nil, nil, tSI, tPI)) then begin
       dwI := WaitForSingleObject(tPI.hProcess, INFINITE);   if (dwI = WAIT_OBJECT_0) then
         if (GetExitCodeProcess(tPI.hProcess, dwI)) then Result := dwI;   CloseHandle(tPI.hProcess);
       CloseHandle(tPI.hThread);
     end;
    end;
      

  2.   

    uses windows;winexec('路径\exp.exe 参数....',swShowNormal);