I have an ID of a running process (launched not by me). How can I get its command line arguments?
Asked
Active
Viewed 2,812 times
1 Answers
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