title: Getting the child processes name from a process id
body: <p><strong>Question</strong></p>
  
  <p>Is it possible to get the name off a running process child?
  and can some one give me a example?</p>
  
  <p>I want to make a program that shows all running processes and there child processes.</p>
  
  <p>I am doing this on a Windows 10 station.
  I am writing in the c++ languages.</p>
  
  <p>What is got so far is:</p>
  
  <pre><code>    // Runningprocess.cpp : Defines the entry point for the console application.
      //
  
      #include "stdafx.h"
      #include &lt;windows.h&gt;
      #include &lt;stdio.h&gt;
      #include &lt;tchar.h&gt;
      #include &lt;psapi.h&gt;
      // To ensure correct resolution of symbols, add Psapi.lib to TARGETLIBS
      // and compile with -DPSAPI_VERSION=1
  
      void PrintProcessNameAndID( DWORD processID )
      {
          TCHAR szProcessName[MAX_PATH] = TEXT("&lt;unknown&gt;");
  
          // Get a handle to the process.
  
          HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
                                         PROCESS_VM_READ,
                                         FALSE, processID );
  
          // Get the process name.
  
          if (NULL != hProcess )
          {
              HMODULE hMod;
              DWORD cbNeeded;
  
              if ( EnumProcessModules( hProcess, &amp;hMod, sizeof(hMod), 
                   &amp;cbNeeded) )
              {
                  GetModuleBaseName( hProcess, hMod, szProcessName, 
                                     sizeof(szProcessName)/sizeof(TCHAR) );
              }
          }
  
          // Print the process name and identifier.
  
          _tprintf( TEXT("%s  (PID: %u)\n"), szProcessName, processID );
  
          // Release the handle to the process.
  
          CloseHandle( hProcess );
      }
  
      int _tmain(int argc, _TCHAR* argv[])
      {
              // Get the list of process identifiers.
  
              DWORD aProcesses[1024], cbNeeded, cProcesses;
              unsigned int i;
  
              if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &amp;cbNeeded ) )
              {
                  return 1;
              }
  
  
              // Calculate how many process identifiers were returned.
  
              cProcesses = cbNeeded / sizeof(DWORD);
  
              // Print the name and process identifier for each process.
  
              for ( i = 0; i &lt; cProcesses; i++ )
              {
                  if( aProcesses[i] != 0 )
                  {
                      PrintProcessNameAndID( aProcesses[i] );
                      //here needs to come a print funtion for the child processes of "aProcesses[i]"
                  }
              }
  
          return 0;
      }
  </code></pre>