#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0

    Find 2 process with the same name


    OK i have 2 process with same name, i use FindWindow but i find the wrong one, i dont know how to skip to the next process,
    my code :
    Code:
    #include <stdio.h>
    #include <Windows.h>
    #include <conio.h>
    void main()
    {
    	DWORD pId;
    	HWND hGame = NULL;
    	hGame = FindWindow(NULL,L"AssaultCube");
    	if(hGame)
    	{
    		GetWindowThreadProcessId(hGame,&pId);
    		printf("%d\n",pId);
    	}else{
    		printf("Game Open failed");	
    	}
    	getch();
    }
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    I don't know what FindWindow does, and I'm not going to look it up.

    I'd get a list of processes and scan that list.

    I'm sure Windows has a command to list processes because I once removed a virus that ran two processes. As soon as I'd kill one the other would start a second process with a different name. No way to stop them by hand through the task manager gui so I wrote a batch script that reduced their process priority then killed them.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,377
    Rep Power
    1871
    <vader>
    I sense a presence in the source, a feeling that I've seen this all before
    </vader>

    > hGame = FindWindow(NULL,L"AssaultCube");
    Did you read the manual page?
    A really useful feature on most manual pages are the "See also" links to related functions. Having found that FindWindow is close, but not quite what you want, the next best thing to do is go and read what the related functions do. If you dig into it a bit, you should find what you need.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0
    Originally Posted by b49P23TIvg
    I don't know what FindWindow does, and I'm not going to look it up.

    I'd get a list of processes and scan that list.

    I'm sure Windows has a command to list processes because I once removed a virus that ran two processes. As soon as I'd kill one the other would start a second process with a different name. No way to stop them by hand through the task manager gui so I wrote a batch script that reduced their process priority then killed them.
    if u dont know what my code does dont waste my time with useless post, at least do a favor and read one function with 2 fking parameters.
    anyway cant kill any of them, cuz 1 is the logs of the other, kill the logs, kill the process i want. cant be done.

    Originally Posted by salem
    <vader>


    > hGame = FindWindow(NULL,L"AssaultCube");
    A really useful feature on most manual pages are the "See also" links to related functions. Having found that FindWindow is close, but not quite what you want, the next best thing to do is go and read what the related functions do. If you dig into it a bit, you should find what you need.
    of course i read it, i have two windows under the same name, so i find the pid i dont want, i need the other to write into.
    i asked, FindWindow probably get 2 process, how do i make him read the other two.

    Comments on this post

    • ptr2void disagrees : Please go away, skr1pt k1dd13
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    186
    Rep Power
    82
    @HelpBot1,

    I thought I would post a vague resolution to your problem. The solution is as follows:

    Call EnumWindows from within a CALLBACK function to enumerate all open windows.

    I'd post a lot more detail, possibly a complete code sample but your attitude just irks me.

    Good luck!

IMN logo majestic logo threadwatch logo seochat tools logo