how to get process info ( to extract process thread id )

This is a discussion on how to get process info ( to extract process thread id ) within the C++ Programming forums, part of the General Programming Boards category; hello all i need to use the api function PostThreadMessage and for the first parameter i need the thread id ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    58

    how to get process info ( to extract process thread id )

    hello all
    i need to use the api function PostThreadMessage and for the first parameter i need the thread id
    and for that i need the process info , my question is how i can get the process info ?
    i need to use this function to kill process from other process . this is after using TerminateProcess does not work
    gives me exit code 259 , i decided to try to use the PostThreadMessage approach
    Thanks

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Have a look at the link posted in #2 here:
    Terminate Process

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    58
    Hello and thanks for the fast reply
    i get get the process handle , by name with this code :

    Code:
    LPSTR  szExeName = "MyProc.exe";
      HANDLE hProcess;
     
      PROCESSENTRY32 Pc = { sizeof(PROCESSENTRY32) };
      HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
      if(Process32First(hSnapshot, &Pc)){
        do{
          if(!strcmp(Pc.szExeFile, szExeName)) {
             hProcess =  OpenProcess(PROCESS_ALL_ACCESS, TRUE, Pc.th32ProcessID);
          }
        }while(Process32Next(hSnapshot, &Pc));
      }


    the problem is that i need to get the process info and from that to extract the thread id
    this is something i didnt find in the link you send
    Thanks

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Your post on CodeGuru has a solution from VictorN, a MVP. Please note that he inquired as to whether or not there was a message queue associated with the thread that you wanted to use for the PostThreadMessage call. His concerns are justified. I got involved with another thead here concerning PostThreadMessage and developed POC code to illustrate the issues of PostThreadMessage along with a couple of third party references to support my POC code.

    I grew weary of the thread and didn't post the POC code etc. and just deleted the code. But there are a few quirks with using PostThreadMessage. In particular, whether or not there is a message queue associated with the thread. So, I would suggest that you avoid using PostThreadMessage unless you thoroughly understand its shortcomings.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. init adopts zombie process?
    By password636 in forum Linux Programming
    Replies: 4
    Last Post: 07-01-2009, 11:05 AM
  2. Thread Prog in C language (seg fault)
    By kumars in forum C Programming
    Replies: 22
    Last Post: 10-09-2008, 02:17 PM
  3. Help needed in creating a process
    By sac_garg in forum C Programming
    Replies: 3
    Last Post: 10-01-2006, 02:40 AM
  4. Process sending file descriptors to another process
    By Yasir_Malik in forum C Programming
    Replies: 4
    Last Post: 04-07-2005, 08:36 PM
  5. MFC Controls and Thread Safety :: MFC
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 12-06-2002, 11:36 AM

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