我要用arj解压一个文件,要求不弹出解压过程的窗口且等待解压完毕再运行后面的程序。查了以前的贴子,还是不能解决。
请高手帮忙看一下。调试一下,谢谢。周一来结帖
1,没执行完毕就执行了后面的程序,
var
cmd:string;
begin
cmd:='arj.exe -y e test.arj';
winexec(pchar(cmd),sw_hide);
......
end;2.尽管不弹出窗口,但那个隐藏的窗口不会自动关闭,所以后面的程序不会执行,造成程序假死机现象。
var
cmd:string;
begin
cmd:='arj.exe -y e test.arj';
winexec(pchar(cmd),sw_hide);
WinExecAndWait32(cmd,1);
......
end;//函数
function TForm1.WinExecAndWait32(FileName: String;
Visibility: Integer): Integer;
var
zAppName:array[0..512] of char;
zCurDir:array[0..255] of char;
WorkDir:String;
StartupInfo:TStartupInfo;
ProcessInfo:TProcessInformation;
begin
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;
StartupInfo.wShowWindow :=SW_HIDE; 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 := -1 { pointer to PROCESS_INF } else begin
WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
//GetExitCodeProcess(ProcessInfo.hProcess,Result);
Result := 0;
end;end;
请高手帮忙看一下。调试一下,谢谢。周一来结帖
1,没执行完毕就执行了后面的程序,
var
cmd:string;
begin
cmd:='arj.exe -y e test.arj';
winexec(pchar(cmd),sw_hide);
......
end;2.尽管不弹出窗口,但那个隐藏的窗口不会自动关闭,所以后面的程序不会执行,造成程序假死机现象。
var
cmd:string;
begin
cmd:='arj.exe -y e test.arj';
winexec(pchar(cmd),sw_hide);
WinExecAndWait32(cmd,1);
......
end;//函数
function TForm1.WinExecAndWait32(FileName: String;
Visibility: Integer): Integer;
var
zAppName:array[0..512] of char;
zCurDir:array[0..255] of char;
WorkDir:String;
StartupInfo:TStartupInfo;
ProcessInfo:TProcessInformation;
begin
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;
StartupInfo.wShowWindow :=SW_HIDE; 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 := -1 { pointer to PROCESS_INF } else begin
WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
//GetExitCodeProcess(ProcessInfo.hProcess,Result);
Result := 0;
end;end;
var
cmd:string;
begin
cmd:='arj.exe -y e test.arj';
/////去掉这个winexec(pchar(cmd),sw_hide);
WinExecAndWait32(cmd,1);
......
end;
var
cmd:string;
begin
cmd:='arj.exe -y e test.arj'; //winexec(pchar(cmd),sw_hide);
//你应把winexec(pchar(cmd),sw_hide);这行屏蔽掉 WinExecAndWait32(cmd,1);
end;
var
cmd:string;
begin
cmd:='arj.exe -y e test.arj';
//winexec(pchar(cmd),sw_hide);
WinExecAndWait32(cmd,1);showmessage('over');
end;屏蔽了那一行程序还是不执行啊。最后的一个提示框怎么不出来呢?
procedure TForm1.BitBtn1Click(Sender: TObject);
var
cmd:string;
begin
cmd:='arj.exe -y e test.arj';
WinExecAndWait32(cmd,1);
ShowMessage('Ok');
end;你再试试,不是点错按钮了吧?