Info on specific process

This is a discussion on Info on specific process within the Windows Programming forums, part of the Platform Specific Boards category; Whats up guys, I was reading this tutorial http://www.codeproject.com/threads/processes.asp and it helped me A LOT but I wondering how can ...

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    38

    Info on specific process

    Whats up guys, I was reading this tutorial http://www.codeproject.com/threads/processes.asp
    and it helped me A LOT but I wondering how can you modify the code so it will only show information on specific process, lets say NotePad.exe, because all I want is to know notepad PID.

  2. #2
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    My function for that:
    Code:
    DWORD GetProcessByFileName(char* name){
        DWORD process_id_array[1024];
        DWORD bytes_returned;
        DWORD num_processes;
        HANDLE hProcess;
        char image_name[256];
        char buffer[256];
        DWORD exitcode;
        EnumProcesses(process_id_array, 256*sizeof(DWORD), &bytes_returned);
        num_processes = bytes_returned/sizeof(DWORD);
        for(int i=0;i<num_processes;i++){
            hProcess=OpenProcess(PROCESS_ALL_ACCESS,TRUE,process_id_array[i]);
            if(GetModuleBaseName(hProcess,0,image_name,256)){
                if(!stricmp(image_name,name)){
                    CloseHandle(hProcess);
                    return process_id_array[i];
                }
            }
            CloseHandle(hProcess);
        }
        return 0;
    }
    It only fails if you have over 256 processes running which I doubt you have.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    38
    Thanks a lot, but I read your code many times and could not figure it out, where do I put the name of the process I want to find? is it GetProcessByFileName(char* name) I replace the name by my process?

  4. #4
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    You'r responce doesn't make much sence, maybe this will help.
    Code:
    DWORD dwPID = GetProcessByFileName("Notepad.exe");
    dwPID is the process ID of the first program running with the file name of "Notepad.exe".

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Check number of times a process is running
    By linuxwolf in forum Windows Programming
    Replies: 6
    Last Post: 10-17-2008, 11:08 AM
  2. Question about getting an info class from another Form
    By Joelito in forum C# Programming
    Replies: 0
    Last Post: 10-16-2006, 01:02 PM
  3. Terminate Process by Specific FullFilePath
    By MattKamil in forum Windows Programming
    Replies: 1
    Last Post: 07-05-2006, 04:15 PM
  4. Process sending file descriptors to another process
    By Yasir_Malik in forum C Programming
    Replies: 4
    Last Post: 04-07-2005, 07:36 PM
  5. process ring
    By gregulator in forum C++ Programming
    Replies: 0
    Last Post: 02-28-2005, 07:21 PM

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