0

I have an ID of a running process (launched not by me). How can I get its command line arguments?

Hamid Pourjam
  • 20,441
  • 9
  • 58
  • 74
user626528
  • 13,999
  • 30
  • 78
  • 146

1 Answers1

2

you can use wmi to get this kind of info

var q = string.Format("select CommandLine from Win32_Process where ProcessId='{0}'", processId);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(q);
ManagementObjectCollection result = searcher.Get();
foreach (ManagementObject obj in result)
    Console.WriteLine("[{0}]", obj["CommandLine"]);
Hamid Pourjam
  • 20,441
  • 9
  • 58
  • 74
  • I found this shortened, simple, answer way better than anything listed on "recommended" link above. I got this small piece of code working fast. – John Cruz Jun 04 '21 at 20:29