title: windows EnumProcesses some process names as <unknown>
body: <p>Hello I have <a href="https://docs.microsoft.com/en-us/windows/desktop/psapi/enumerating-all-processes" rel="nofollow noreferrer">this</a> sample code running which uses x to print processNames and PIDS of all currently running processes. Only some of them display an actual name though, with others displaying as  (as seen in my output image below)</p>
  
  <p><a href="https://i.stack.imgur.com/4tbOq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4tbOq.png" alt="enter image description here"></a> </p>
  
  <p>I was wondering if this was expected behavior, and that not all processes have a name (I could see this being the case for minimal background processes), or if I was using the EnumProcesses function incorrectly.</p>
  
  <p>My code is:</p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;tchar.h&gt;
  #include &lt;psapi.h&gt;
  #include &lt;tlhelp32.h&gt;
  #include &lt;tchar.h&gt;
  
  
  //https://docs.microsoft.com/en-us/windows/desktop/psapi/enumerating-all-processes
  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 );
  }
  
  //https://docs.microsoft.com/en-us/windows/desktop/psapi/enumerating-all-processes
  int main( void ){
      // 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++ ){
      for ( i = 0; i &lt; 3; i++ ){
          if( aProcesses[i] != 0 )        {
              _tprintf( TEXT("aProcesses[%u] = %u (process ID)\n"), i, aProcesses[i] );
              PrintProcessNameAndID( aProcesses[i] );
              ListProcessThreads( aProcesses[i] );
          }
      }
      return 0;
  }
  </code></pre>