• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

Application is responding

I only know the exe-name (eg prog.exe) how can i find out if the application is still running or hang up ?
0
kostamania
Asked:
kostamania
2 Solutions
 
loop_untilCommented:
See this...

http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20533923.html


You can use

   h:=findwindow('prog',nil);

To find your EXE but it does not mean it will be the exact prog.exe program...


Anyhow, hope it helps.
Have a nice day! :)
0
 
DaFoxCommented:
Hi.

This is how you could do it (on NT you have to use PSAPI to enumerate through the windows):

{ uses TlHelp32 }

type
  TEnumData = packed record
    Wnd: hWnd;
    pID: DWord;
  end;

function EnumProc(hw: hWnd; var data: TEnumData): Bool; stdcall;
var
  pID: DWORD;
begin
  Result := True;
  if (GetWindowLong(hw, GWL_HWNDPARENT) = 0) and (IsWindowVisible( hw ) or IsIconic(hw)) then
  begin
    GetWindowThreadProcessID(hw, @pID);
    if (pID = data.pID) then
    begin
      data.Wnd := hW;
      Result := False;
    end;
  end;
end;

function WindowFromProcessID(pID: DWord): hWnd;
var
  data: TEnumData;
begin
  data.pID := pID;
  data.Wnd := 0;
  EnumWindows(@EnumProc, longint(@data));
  Result := data.Wnd;
end;

function WindowFromAppname32(appname: String): hWnd;
var
  snapshot: THandle;
  processEntry : TProcessEntry32;
begin
  Result := 0;
  snapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0 );
  if (snapshot <> 0) then
  try
    processEntry.dwSize := Sizeof(processEntry);
    if Process32First(snapshot, processEntry) then
    repeat
      if AnsiCompareText(appname, ExtractFilename( StrPas(processEntry.szExeFile))) = 0 then
      begin
        Result:= WindowFromProcessID(processEntry.th32ProcessID);
        break;
      end;
    until not Process32Next(snapshot, processEntry);
  finally
    CloseHandle(snapshot);
  end;
end;


procedure TForm1.Button1Click(Sender: TObject);
var
  Wnd: hWnd;
  dw: DWord;
begin
  Wnd := WindowFromAppName32('delphi32.exe');
  if SendMessageTimeout(Wnd, WM_NULL, 0, 0, SMTO_ABORTIFHUNG, 5000, dw) = 0 then ShowMessage('Panic!! Delphi is not responding') else ShowMessage(':o)');
end;

Best wishes,
Markus
0
 
CleanupPingCommented:
kostamania:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
kacorretiredCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:
       to split points between loop_until and DaFox
 Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Merry Christmas and happy new year!

kacor
EE Cleanup Volunteer
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now