Marco Gasi
asked on
Application freezes after ShellExecuteEx
Hi all.
After the execution of this function (which I use to merge a .reg file into the Windows registry), application freezes: the file is merged I see the usual prompts which ask for merging file and confirming the merging has been successful, then The Explorer window when I started my app brings to front and my application can't get focus.
Any idea?
Thanks to all in advance.
Marco
After the execution of this function (which I use to merge a .reg file into the Windows registry), application freezes: the file is merged I see the usual prompts which ask for merging file and confirming the merging has been successful, then The Explorer window when I started my app brings to front and my application can't get focus.
Any idea?
function TfrmMain.RunAsAdmin(hWnd: HWND; aFile,
aParameters: String): Boolean;
var
sei: TShellExecuteInfo;
ExitCode: DWord;
begin
Result := False;
FillChar(sei, SizeOf(sei), 0);
sei.cbSize := SizeOf(sei);
sei.Wnd := hWnd;
sei.fMask := SEE_MASK_NOCLOSEPROCESS or SEE_MASK_UNICODE;
sei.lpFile := PChar(aFile);
sei.lpParameters := PChar(aParameters);
sei.nShow := SW_SHOWNORMAL;
if ShellExecuteEx(@sei) then
begin
repeat
Application.ProcessMessages;
GetExitCodeProcess(sei.hProcess, ExitCode) ;
until (ExitCode <> STILL_ACTIVE) or
Application.Terminated;
result := True;
end;
end;
Thanks to all in advance.
Marco
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Cheers