Handle of all running processes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thomasjino
    New Member
    • Sep 2006
    • 5

    Handle of all running processes

    Hi...
    How can i get handle of all running processes using VC++ code.
    I have to find a particular window and do minimise that..
    Can anyone help me.....
  • abhisoni
    New Member
    • Dec 2007
    • 12

    #2
    Hi,
    First get the snapshot of all the processes running in the system, at that time by using

    CreateToolhelp3 2Snapshot ().

    Now retrieve the info regarding the first process by using Process32First( ).

    Open the existing process object by OpenProcess ().

    Ues a loop to enumerate through all the processes. You can use

    PROCESSENTRY32 pe32;
    while (!Process32Next (hProcess,&pe32 ))

    In the loop again call OpenProcess for every process.

    You can get the info regarding the process from the PROCESSENTRY32 structure.

    remember to close the Handles after the loop is over i.e. after the loop.

    Comment

    • thomasjino
      New Member
      • Sep 2006
      • 5

      #3
      Hi,,,
      Thanks for your reply...

      Actually i have tried to use the CreateToolhelp3 2Snapshot()
      but it is showing undeclared identifier error...
      I am using VC++ 6.0; and using MFC. So can u please explain the above in detail form..


      Thanking YOu once again....

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Did you #include <Tlhelp32.h> ??

        Comment

        • thomasjino
          New Member
          • Sep 2006
          • 5

          #5
          Hi,

          Thankx.....

          I did include the header file and then got corrected...

          Thankx a lot...

          Comment

          • thomasjino
            New Member
            • Sep 2006
            • 5

            #6
            Hi,,
            As per the previous codings
            I have got the handle of all running process.
            I am getting the id of all processes too.

            Still my problem is unable to solve.
            That is , the particular window cannot be minimized.
            The ShowWindow() minimizes the application program only.

            Which is the other function to do minimise or any of the operations to the window.


            Thanx in advance...

            Comment

            • abhisoni
              New Member
              • Dec 2007
              • 12

              #7
              How r u obtaining the Handle of a particular process ?

              I think the problem might be ith the handle that u r passing in the Showwindow ()
              U can get the handle of a process by using following function..

              HANDLE OpenProcess(
              DWORD dwDesiredAccess ,
              BOOL bInheritHandle,
              DWORD dwProcessId
              );

              I have done this and it works fine.

              Comment

              • thomasjino
                New Member
                • Sep 2006
                • 5

                #8
                Thanks for your reply...

                I am getting handle also..

                And i have tried to get control(my aim is to minimise ) over the windows which is currently running(Eg IE,OUtlook,VC editor.. like ).. The code i have done

                HANDLE hproc=(HANDLE)C reateToolhelp32 Snapshot (TH32CS_SNAPPRO CESS,0);
                PROCESSENTRY32 pentry;
                Process32First( hproc,&pentry);

                HANDLE htemp;
                HWND m_hactive;
                while (Process32Next( hproc,&pentry))
                {

                HANDLE ps = OpenProcess( SYNCHRONIZE|PRO CESS_TERMINATE,
                FALSE,pentry.th 32ProcessID);

                m_hactive=(HWND )htemp;//This i have done for converting handle to hwnd.. I dont no whether it is correct
                :: ShowWindow(m_ha ctive,SW_FORCEM INIMIZE)/*i did this first to minimising all Windows.. But does not work.*/
                ::TerminateProc ess(htemp,GetEx itCodeProcess(h temp,&tmpstr));

                CloseHandle(ps)
                }

                Comment

                • abhisoni
                  New Member
                  • Dec 2007
                  • 12

                  #9
                  Set the size of the PROCESSENTRY32 structure before using it.

                  Try OpenProcess () with PROCESS_ALL_ACC ESS, PROCESS_SET_INF ORMATION and PROCESS_QUERY_I NFORMATION. The options that u have chosen are for terminating the process.

                  Also try to use SW_MINIMIZE instead of SW_FORCEMINIMIZ E.

                  In good programming, always perform the NULL checks, for everything u r suspicious about.

                  Do let me know the results........ ...

                  Comment

                  Working...