|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Question on WMI and System.Management classThe code below enumerates all products installed on any given machine. Through System.Management i can also find WMI methods that could be exected. But i have not worked on WMI and System.Management before, i need to know how to execute the those mehtods ConnectionOptions options = new ConnectionOptions(); options.Authority = "NTLMDOMAIN:DOMAIN_X"; options.Username = "xyz"; options.Password = "xyz123"; string Machine = "abc"; ManagementScope scope = new ManagementScope("\\\\" + Machine + "\\root\\CIMv2", options); scope.Connect(); //Query system for all Installed products information ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_Product"); ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query); // Call Get() to retrieve the collection of objects and loop through it textBoxPrinters.Text = textBoxPrinters.Text + "*** Applications on '" + Machine + " are\r\n"; foreach (ManagementBaseObject oPrinter in searcher.Get()) { textBoxPrinters.Text = textBoxPrinters.Text + oPrinter["Name"].ToString() + "\r\n"; } //Get the object on which the method will be invoked ManagementClass processClass = new ManagementClass("Win32_Product"); textBoxPrinters.Text = textBoxPrinters.Text + "\r\n\r\n**** Methods ****\r\n"; foreach(MethodData oPrinterMethods in processClass.Methods) { Diagnostics.WriteLine(processClass.Methods[oPrinterMethods.Name.ToString() } When you execute this code it will write following line to console output... *** Applications on 'abc' are Microsoft Windows Services for UNIX Program Files Microsoft FrontPage Client - English Camera Window DS Microsoft SQL Server VSS Writer Microsoft AntiSpyware Microsoft .NET Compact Framework 2.0 Microsoft SQL Server 2005 Mobile [ENU] Developer Tools ...... **** Methods ***** Install Admin Advertise Reinstall Upgrade Configure Uninstall What i wan to know is... how do i execute the methods above?? - Thanks Gancy |
|||||||||||||||||||||||