In early 2000, Mike Woodring moved Heaven and Earth to write a tool that would inject a DLL into a process’s memory for purposes of finding the command line with which the process was launched. While hanging around Don and Tim this week, Don was all hot on WMI, so we fired it up in .NET and rebuilt Mike’s tool like so:
using System; using System.Management; class cmdline { staticvoidMain(string[] args) { if( args.Length != 1 ) { Console.WriteLine(“usage: cmdline <processId>“); return; }
ManagementObject obj = new ManagementObject(string.Format(“Win32_Process.Handle="{0}\“”, args[0])); Console.WriteLine(obj.Properties[“CommandLine”].Value); } }
This makes WMI pretty darn cool in my book. I’ll be reading Jon Fancey’s article on WMI + .NET in the latest MSDN Magazine.
BTW, I have to admit that I’m nowhere near as manly as Mike. I’ll take this sissy code any day. : )
Don “XML” worked a
little PhotoShop magic on a poster for a movie that I loved growing up (it was
one of two record albums I had and I listened to it over and over and over):