本文整理自网络,侵删。
用 Delphi 的 WinExec() 调用 WinRar 的命令行方式,解压缩文件,能够得到调用是否成功的返回值,可是,如何能够得到 WinRar 在处理解压缩文件后的返回值?
WinRar退出值
RAR 成功操作后返回 0 。非 0 返回码意味着操作由于某种错误被取消:
255 用会中断 用户中断操作
8 内存错误 没有足够的内存进行操作
7 用户错误 命令行选项错误
6 打开错误 打开文件错误
5 写错误 写入磁盘错误
4 被锁定档案 试图修改先前锁定的档案文件
使用 'k' 命令
3 CRC 错误 解压缩时发生一个 CRC 错误
2 致命错误 发生一个致命错误
1 警告 没有发生致命错误
0 成功 操作成功
function AddToRAR(RarDir, ArchiveName, FileNames, ArchiveOptions : string): integer;
var
PChTmp : PChar;
ExitCodes : dword; si : STARTUPINFO;
pi : PROCESS_INFORMATION;
begin
PChTmp := PChar(RarDir + '\rar.exe a ' + ArchiveName + ' ' + FileNames + ' ' + ArchiveOptions);
ZeroMemory(@si, sizeof(si));
si.cb := SizeOf(si);
if not CreateProcess( nil, PChTmp, nil, nil, False, 0, nil, nil, si, pi ) then
begin
ExitCodes := 999;
end
else
begin
WaitForSingleObject(pi.hProcess, INFINITE);
GetExitCodeProcess(pi.hProcess, ExitCodes);
end;
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
result := ExitCodes;
end;
相关阅读 >>
Delphi getdrivetypea() 查看驱动器类型
Delphi使用tnethttpclient:重定向后如何给出最终的url?
更多相关阅读请进入《Delphi》频道 >>