Detecting a running application

Any idea how to tell if a certain application is running i.e explorer.exe?
aroaraAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MadshiCommented:
That depends on the application. You can check for the existence of the explorer very easily by e.g. doing this:

  if FindWindow('Shell_TrayWnd', '') <> 0 then
    ShowMessage('Explorer is running!');

That means you can use FindWindow if you know the caption or the class of a window that ONLY this specific process, you're looking for, uses.

But it gets a bit more complicated, when you need to know that for applications where you don't know anything about which windows they open.

If you have D4 or D5, you can download the free unit "enumStuff.pas" from my homepage:

http://beam.to/madshi

Use the function GetProcessList to get a list of all currently running processes. This functions works under both win9x and winNT.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ipp1123Commented:
Dear aroara,

There is a way to check if a certain application is active and this is
not that difficult to accomplish but you have to use Win32 API. There
exists a function called FindWindow you can use to do the trick. I'll
give you an example with Notepad.exe:

Here is an OnClick event of a button:

procedure TForm1.Button1Click(Sender: TObject);
var WinHandle : HWND;
begin
 WinHandle:=FindWindow(nil, 'Untitled - Notepad');
 if WinHandle <> 0 then ShowMessage('Notepad Active!') else ShowMessage('Notepad Not Active!');
end;

The first parameter of FindWindow is the class name that can be left nil. For the second you
need to pass as a parameter the title of the main window for your program. The function doesn't
search for child windows. I really do believe this short fragment of code would help you.

Best regards, Ivan Petrov
0
MadshiCommented:
Hi Ivan, welcome to the EE-family...   :-)

Regards, Madshi.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

ipp1123Commented:
Thanks for the warm welcome, Madshi!

Take care, Ivan.
0
the_realCommented:
Just a comment to the FindWindow function...

eg If you want to test if notepad is running and you test it with 'Untitled - Notepad', what then if the user have loaded a file, then it's 'myfile.txt - Notepad', or if the user uses another language of Windows, eg I'm Danish, so for me it would be: 'Ikke-navngivet - Notesblok'. Also, to madshi, if you are using another shell than Explorer, then there'll also be a 'Shell_TrayWnd', so you cant be certain that explorer is running just by checking 'Shell_TrayWnd'

Just my comment...

The_Real
0
MadshiCommented:
Yes, but the question is about a specific executable, not about the shell...   :-)
But you're right. Finding a window is not the best way. That's why I suggested using my process enumeration unit.

Regards, Madshi.
0
duke_nCommented:
watching...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.