Check Running Process Dev-C++

This is a discussion on Check Running Process Dev-C++ within the Windows Programming forums, part of the Platform Specific Boards category; Im in the middle of creating a DLL for Game Maker (some people may know of it) and i need ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    3

    Check Running Process Dev-C++

    Im in the middle of creating a DLL for Game Maker (some people may know of it) and i need a way to check if a certain process is running. For example notepad.exe. If it is running return true, otherwise return false. I would appreciate any help to getting this done. Thanks.

  2. #2
    Registered User
    Join Date
    Oct 2005
    Posts
    29
    one way to do it is like this:
    Code:
    bool isRunning(string pName)
    {
    	unsigned long aProcesses[1024], cbNeeded, cProcesses;
    	if(!EnumProcesses(aProcesses, sizeof(aProcesses), &cbNeeded))
    		return;
    
    	cProcesses = cbNeeded / sizeof(unsigned long);
    	for(unsigned int i = 0; i < cProcesses; i++)
    	{
    		if(aProcesses[i] == 0)
    			continue;
    
    		HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0, aProcesses[i]);
    		char buffer[50];
    		GetModuleBaseName(hProcess, 0, buffer, 50);
    		CloseHandle(hProcess);
    		if(pName == string(buffer))
    			return true;
    	}
    	return false;
    }
    Last edited by lord mazdak; 04-09-2007 at 07:27 PM.

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    3
    Hey thanks for that. I'm getting one error when trying to compile though:

    Code:
    error C2664: 'GetModuleBaseNameW' : cannot convert parameter 3 from 'char [50]' to 'LPWSTR'
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    Code:
    GetModuleBaseName(hProcess, 0, buffer, 50);

  4. #4
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    308
    1. Remove unicode defines in your project setings

    or

    2. Change from char buffer[50] to wchar_t (or any unicode types)

    or

    3. Change from GetModuleBaseNameW to GetModuleBaseNameA

    Is the wonderfull world of ANSI vs UNICODE
    Last edited by Joelito; 04-10-2007 at 08:22 AM.
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  5. #5
    Registered User
    Join Date
    Apr 2007
    Posts
    3
    Thanks, I've got it all working perfectly now. One more question. Is it possile to get the the path to the exe of the process? Thanks

  6. #6
    Registered User
    Join Date
    Oct 2005
    Posts
    29
    yeah, or atleast you can get the absolute path to the exe, somewhat like this:
    Code:
    string getFilename(const unsigned long &processID)
    {
    	HANDLE process;
    	process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0, processID);
    	char buffer[256];
    	GetModuleFileNameEx(process, 0, buffer, 256);
    	CloseHandle(process);
    	return buffer;
    }

  7. #7
    Registered User
    Join Date
    Feb 2008
    Posts
    6
    hello i'm new to programing and i'm trying to monitor certain process and the posted code can do that for me but i have troubles compileing it and i was wondering witch heder files should i include thanks in advance
    Last edited by vlad26; 02-03-2008 at 03:52 PM.

  8. #8
    Registered User jian2587's Avatar
    Join Date
    Feb 2008
    Location
    NY
    Posts
    11
    windows.h

  9. #9
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Quote Originally Posted by vlad26 View Post
    hello i'm new to programing and i'm trying to monitor certain process and the posted code can do that for me but i have troubles compileing it and i was wondering witch heder files should i include thanks in advance
    You'll need windows.h, psapi.h and you'll have to link in psapi.lib

  10. #10
    Registered User
    Join Date
    Feb 2008
    Posts
    6
    ok thanks but i have another problem now ((( i've linked psapi.h and included windows.h
    but it's doesn't want to compile i'm getting this return without a value errors help please????
    thanks in advance




    return-statement with no value, in function returning 'int'

  11. #11
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Quote Originally Posted by vlad26 View Post
    ok thanks but i have another problem now ((( i've linked psapi.h and included windows.h
    but it's doesn't want to compile i'm getting this return without a value errors help please????
    thanks in advance




    return-statement with no value, in function returning 'int'
    change this
    Code:
    if(!EnumProcesses(aProcesses, sizeof(aProcesses), &cbNeeded))
    		return;
    to this:
    Code:
    if(!EnumProcesses(aProcesses, sizeof(aProcesses), &cbNeeded))
    		return false;

  12. #12
    Registered User
    Join Date
    Feb 2008
    Posts
    6
    thanks it's working fine.Now i have another question i know i'm asking too much but, if my program name is vlad26.exe , how to change it's process name to be for example like this: vlad26process.exe
    Last edited by vlad26; 02-05-2008 at 05:04 PM.

  13. #13
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    rename the file.

  14. #14
    Registered User
    Join Date
    Feb 2008
    Posts
    6
    Quote Originally Posted by robwhit View Post
    rename the file.
    No, my point was to change the process name without renaming the program.

  15. #15
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Quote Originally Posted by vlad26 View Post
    No, my point was to change the process name without renaming the program.
    If you have access to the Windows DDK, then check out the documentation on the System Class Information structure. One field, UNICODESTRING processname is classified as read only. Thus, it cannot be modifed meaning that you cannot change the name of a process in task manager.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 03-14-2009, 02:03 PM
  2. allegro issues
    By mramazing in forum C++ Programming
    Replies: 1
    Last Post: 01-07-2009, 10:56 PM
  3. Help needed in creating a process
    By sac_garg in forum C Programming
    Replies: 3
    Last Post: 10-01-2006, 01:40 AM
  4. multithreading question
    By ichijoji in forum C++ Programming
    Replies: 7
    Last Post: 04-12-2005, 10:59 PM
  5. Process sending file descriptors to another process
    By Yasir_Malik in forum C Programming
    Replies: 4
    Last Post: 04-07-2005, 07:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21