Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C 

How to check if a program is running?

Hello

I want to check if a program is running.
Like this:
PHP Code

<?php 
    bool x
("notepad.exe" == true); {
         
system("taskkill /f /im notepad.exe >nul");
        } else {
            goto 
con;
        }
con:
... 

If notepad.exe is active, taskkill it. Else go to label con.
I know that booleans are true or false, but I don't know how to check if boolean x is valid or not.

Anyway,
Thanks for reading,
Niely
It's very easy:
- try to find the window handle
- GetWindowThreadProcessId
- etc
- GetModuleFileNameEx
- etc

BTW why would you kill something as harmless as Notepad?
(May 11, 2014 04:41 AM)Masm4ever Wrote:  It's very easy:
- try to find the window handle
- GetWindowThreadProcessId
- etc
- GetModuleFileNameEx
- etc

BTW why would you kill something as harmless as Notepad?

He's probably doing it for testing purposes :)
^It's indeed for testing. :)

I did some research and I found something about HWND, but how can I use it now and check if a program is running?

Code
bool isRunning(LPCSTR pName)
{
    HWND hwnd;
    hwnd = FindWindow(NULL, pName);
    if (hwnd != 0) {
        return true;
    } else {
        return false;
    }
}
Why the HWND hwnd; why LPCSTR; and why the program name twice?

I understand the logic about the code, but I want to know the details too.

Thanks! :)
hWnd -> Window handle
LPCSTR, program name -> http://msdn.microsoft.com/en-us/library/...85%29.aspx

OMG where did you find that lousy convoluted piece of crap???? It should be
Code
bool isRunning(LPCSTR pName)
{
    return (bool) FindWindow(NULL, pName);
}

And even that is an overkill.
(May 11, 2014 02:02 PM)Masm4ever Wrote:  OMG where did you find that lousy convoluted piece of crap???? It should be
Code
bool isRunning(LPCSTR pName)
{
    return (bool) FindWindow(NULL, pName);
}

And even that is an overkill.

Code
HWND isRunning(LPCSTR pName)
{
    return FindWindow(NULL, pName);
}

Quote:If the function succeeds, the return value is a handle to the window that has the specified class name and window name.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.


So in essence, his wrapper function for FindWindow is completely redundant.
If you want to check if a process is running use "Tl32Help" and check if a process with the name is active.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by Takehito MorokuzuMay 5, 2018 12:21 PM 9 372 May 5, 2018 12:21 PM
Last Post: He B TeMy
[C#] by ( ͡° ͜ʖ ͡°)Oct 20, 2012 06:27 AM 26 649 Oct 20, 2012 06:27 AM
Last Post: Daedun
[.NET] by xXx pR0 h4X0r xXxFeb 23, 2012 12:40 PM 9 166 Feb 23, 2012 12:40 PM
Last Post: ★Cooldude★