You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ThreadUtil.cs 932 B

12345678910111213141516171819202122232425262728293031
  1. using System.Diagnostics;
  2. using System.Management;
  3. using System.Text;
  4. namespace Shadowsocks.Util.ProcessManagement
  5. {
  6. static class ThreadUtil
  7. {
  8. /*
  9. * See:
  10. * http://stackoverflow.com/questions/2633628/can-i-get-command-line-arguments-of-other-processes-from-net-c
  11. */
  12. public static string GetCommandLine(this Process process)
  13. {
  14. var commandLine = new StringBuilder(process.MainModule.FileName);
  15. commandLine.Append(" ");
  16. using (var searcher = new ManagementObjectSearcher("SELECT CommandLine FROM Win32_Process WHERE ProcessId = " + process.Id))
  17. {
  18. foreach (var @object in searcher.Get())
  19. {
  20. commandLine.Append(@object["CommandLine"]);
  21. commandLine.Append(" ");
  22. }
  23. }
  24. return commandLine.ToString();
  25. }
  26. }
  27. }