Reading Command Line Arguments of Another Process (Win32 C code)

后端 未结 5 1556
甜味超标
甜味超标 2020-12-16 02:41

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

5条回答
  •  温柔的废话
    2020-12-16 03:30

    To answer my own question, I finally found a CodeProject solution that does exactly what I'm looking for:

    http://www.codeproject.com/KB/threads/GetNtProcessInfo.aspx

    As @Reuben already pointed out, you can use NtQueryProcessInformation to retrieve this information. Unfortuantely it's not a recommended approach, but given the only other solution seems to be to incur the overhead of a WMI query, I think we'll take this approach for now.

    Note that this seems to not work if using code compiled from 32bit Windows on a 64bit Windows OS, but since our modules are compiled from source on the target that should be OK for our purposes. I'd rather use this existing code and should it break in Windows 7 or a later date, we can look again at using WMI. Thanks for the responses!

    UPDATE: A more concise and C only (as opposed to C++) version of the same technique is illustrated here:

    http://wj32.wordpress.com/2009/01/24/howto-get-the-command-line-of-processes/

提交回复
热议问题