【发布时间】:2011-06-14 19:23:24
【问题描述】:
我有以下创建进程的函数:
function .CreateProcess(aAppletPath: string; var aError : string; aProcessInfo: TProcessInformation): Boolean;
var
StartInfo: TStartupInfo;
begin
FillChar(StartInfo, SizeOf(TStartupInfo),#0);
FillChar(aProcessInfo, SizeOf(TProcessInformation),#0);
StartInfo.cb := SizeOf(TStartupInfo);
if False then begin
StartInfo.dwFlags := STARTF_USESHOWWINDOW;
StartInfo.wShowWindow := SW_HIDE;
end;
if Windows.CreateProcess(nil, PChar(aAppletPath), nil, nil, False, CREATE_NEW_PROCESS_GROUP + NORMAL_PRIORITY_CLASS, nil, nil, StartInfo, aProcessInfo) then begin
Result := True;
WaitForInputIdle(aProcessInfo.hProcess, oTimeOutSecs * 1000);
end
else begin
Result := False;
end;
end;
我有这个等待应用程序终止的方法:
function WaitForProcessTerminate(aHandle: THandle) : Boolean;
var
vResult : LongWord;
Msg: TMsg;
PHandles: Pointer;
begin
vResult := 0;
PHandles := @aHandle;
PeekMessage(Msg, 0, 0, 0, PM_NOREMOVE);
while True do begin
vResult := Windows.MsgWaitForMultipleObjects(1, PHandles^, False, oTimeOutSecs * 1000, QS_ALLINPUT);
if vResult = WAIT_OBJECT_0 + 1 then begin
if PeekMessage(Msg, 0, 0, 0, PM_REMOVE) then begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end
else begin
Break;
end;
end;
case vResult of
WAIT_ABANDONED: Result := False;
WAIT_OBJECT_0: Result := True;
WAIT_TIMEOUT: Result := False;
else begin
Result := False;
end;
end;
if not Result then begin
ShowMessage(SystemErrorMessage);
end;
end;
问题是等待函数总是返回带有Access denied 消息的WAIT_FAILED。我究竟做错了什么?此代码是 Delphi 2010,我调用的应用程序是 java 应用程序。
【问题讨论】:
-
在拨打
CreateProcess之前请先拨打UniqueString(aAppletPath); API 被允许修改你传递给它的字符串,所以你应该确保 your 调用者也不会得到一个修改后的值作为回报。