0

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

Hamid Pourjam
  • 19,792
  • 9
  • 57
  • 71
user626528
  • 13,362
  • 27
  • 71
  • 139

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
  • 19,792
  • 9
  • 57
  • 71
  • 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