shellexecute(handle,nil, 'winrar', PChar('a   '+ExtractFilePath(Application.ExeName)+ParamsList[0]+'.rar   '+ExtractFilePath(Application.ExeName)+ParamsList[0]),nil,SW_SHOW);我用这个来压缩文件,压缩完成后客户端通过FTP从服务器下载,请问应该如何等待执行完成,如果用CreateProcess+WaitForSingleObject的话,CreateProcess里面如何给winrar传参数,麻烦大家了

解决方案 »

  1.   


    function WinExecAndWait32(Filename: String; Visibility: Integer): Cardinal;
    var
      zAppName: array [0 .. 512] of Char;
      zCurDir: array [0 .. 255] of Char;
      WorkDir: String;
      StartupInfo: TStartupInfo;
      ProcessInfo: TProcessInformation;begin
      // Result := -1;
      StrPCopy(zAppName, Filename);
      GetDir(0, WorkDir);
      StrPCopy(zCurDir, WorkDir);
      FillChar(StartupInfo, Sizeof(StartupInfo), #0);
      StartupInfo.cb := Sizeof(StartupInfo);  StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
      StartupInfo.wShowWindow := Visibility;
      if not CreateProcess(nil, zAppName, { pointer to command line string }
        nil, { pointer to process security
          attributes }
        nil, { pointer to thread security
          attributes }
        False, { handle inheritance flag }
        CREATE_NEW_CONSOLE or { creation flags }
        NORMAL_PRIORITY_CLASS, nil, { pointer to new environment block }
        nil, { pointer to current directory name }
        StartupInfo, { pointer to STARTUPINFO }
        ProcessInfo) then
        Result := $FF { pointer to PROCESS_INF }  else
      begin
        WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
        GetExitCodeProcess(ProcessInfo.hProcess, Result);
      end;
    end;//调用
    WinExecAndWait32(FilePath + 'formats\mktargz.bat', SW_NORMAL);
      

  2.   

    //把文件夹 Bitmaps 中全部的文件添加到 RAR 压缩文件 Pictures 中:
    WinExecAndWait32('WinRAR a Pictures.rar Bitmaps', SW_NORMAL);