我想用如下方法,却不行#########################################var
h: cardinal;
hd: HDC;
begin
showmessage('start...');
h := ShellExecute(Application.Handle, 'open',
'C:\test.bat',
nil,
nil,
SW_shownormal);
WaitForInputIdle(h, INFINITE);
showmessage('end...');
end;######################################可是WaitForInputIdle在dos窗口打开时就执行完了,而不是在bat中的dos命令运行完后(或dos窗口关闭后)执行完的,请教……
h: cardinal;
hd: HDC;
begin
showmessage('start...');
h := ShellExecute(Application.Handle, 'open',
'C:\test.bat',
nil,
nil,
SW_shownormal);
WaitForInputIdle(h, INFINITE);
showmessage('end...');
end;######################################可是WaitForInputIdle在dos窗口打开时就执行完了,而不是在bat中的dos命令运行完后(或dos窗口关闭后)执行完的,请教……
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
begin
cmdstr:=pchar('C:\test.bat');
fillchar(StartupInfo,sizeof(StartupInfo),0);
CreateProcess(nil,cmdstr,nil,nil,false,0,nil,nil,StartupInfo,Pro
cessInfo);
With ProcessInfo do begin
CloseHandle(hThread);
WaitForSingleObject(hProcess, INFINITE);
CloseHandle(hProcess);
end;
end;
果然,马上给分,不过还有事请教#1: CreateProcess(nil,cmdstr,nil,nil,false,0,nil,nil,StartupInfo,ProcessInfo);
#2: With ProcessInfo do begin
#3: CloseHandle(hThread);
#4: WaitForSingleObject(hProcess, INFINITE);
#5: CloseHandle(hProcess);
#6: end; 就是#3起什么作用?我注释掉也可以实现啊?
还有我在
h := ShellExecute(
之后调用
WaitForSingleObject(h, INFINITE);
为什么不可以?
为什么ProcessID可以作为一个互斥对象而Application_Instance_Handle不行?