Link to home
Start Free TrialLog in
Avatar of Marco Gasi
Marco GasiFlag for Spain

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?

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;

Open in new window


Thanks to all in advance.
Marco
ASKER CERTIFIED SOLUTION
Avatar of Geert G
Geert G
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Marco Gasi

ASKER

Thanks, Geert. It seems the problem is in another part of my code and when I'll find where I'll post a new question. But I award points fr the interesting resource I didn't knew :)

Cheers