Solved

Application freezes after ShellExecuteEx

Posted on 2013-06-16
2
745 Views
Last Modified: 2013-06-16
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
0
Comment
Question by:Marco Gasi
2 Comments
 
LVL 37

Accepted Solution

by:
Geert Gruwez earned 500 total points
ID: 39251632
try delphidabblers code ExecAndWait under windows shell

http://snippets.delphidabbler.com/
0
 
LVL 31

Author Closing Comment

by:Marco Gasi
ID: 39252230
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
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
delphi prevent click fast 2 242
Delphi XE10 Round Image 2 162
How to convert memory stream to PDF file 6 125
DBCtrlGrid, Delphi, Scroll 7 26
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question