?
Solved

Application is responding

Posted on 2003-02-28
5
Medium Priority
?
173 Views
Last Modified: 2010-05-18
I only know the exe-name (eg prog.exe) how can i find out if the application is still running or hang up ?
0
Comment
Question by:kostamania
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 3

Accepted Solution

by:
loop_until earned 100 total points
ID: 8046048
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
 
LVL 6

Assisted Solution

by:DaFox
DaFox earned 100 total points
ID: 8047509
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
 

Expert Comment

by:CleanupPing
ID: 9317022
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
 
LVL 10

Expert Comment

by:kacor
ID: 9992570
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month9 days, 8 hours left to enroll

762 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