title: Reading Command Line Arguments of Another Process (Win32 C code)
body: <p>I need to be able to list the command line arguments (if any) passed to other running processes. I have the PIDs already of the running processes on the system, so basically I need to determine the arguments passed to process with given PID <em>XXX</em>. </p>
  
  <p>I'm working on a core piece of a <a href="http://code.google.com/p/psutil/" rel="noreferrer">Python module for managing processes</a>. The code is written as a Python extension in C and will be wrapped by a higher level Python library. The goal of this project is to avoid dependency on third party libs such as the pywin32 extensions, or on ugly hacks like calling 'ps' or taskkill on the command line, so I'm looking for a way to do this in C code.</p>
  
  <p>I've Googled this around and found some brief suggestions of using <a href="http://msdn.microsoft.com/en-us/library/ms682437(VS.85).aspx" rel="noreferrer">CreateRemoteThread()</a> to inject myself into the other process, then run <a href="http://msdn.microsoft.com/en-us/library/ms683156(VS.85).aspx" rel="noreferrer">GetCommandLine()</a> but I was hoping someone might have some working code samples and/or better suggestions.</p>
  
  <p><strong>UPDATE</strong>: I've found full working demo code and a solution using NtQueryProcessInformation on CodeProject: <a href="http://www.codeproject.com/KB/threads/GetNtProcessInfo.aspx" rel="noreferrer">http://www.codeproject.com/KB/threads/GetNtProcessInfo.aspx</a> - It's not ideal since it's "unsupported" to cull the information directly from the NTDLL structures but I'll live with it. Thanks to all for the suggestions. </p>
  
  <p><strong>UPDATE 2</strong>: I managed through more Googling to dig up a C version that does not use C++ code, and is a little more direct/concisely pointed toward this problem. See <a href="http://wj32.wordpress.com/2009/01/24/howto-get-the-command-line-of-processes/" rel="noreferrer">http://wj32.wordpress.com/2009/01/24/howto-get-the-command-line-of-processes/</a> for details.</p>
  
  <p>Thanks!</p>