using System; using System.Management; using System.Windows.Forms; namespace WMISample { public class MyWMIQuery { public static void Main() { try { ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\Microsoft\\Windows\\TaskScheduler", "SELECT * FROM MSFT_ScheduledTask WHERE State = 4"); foreach (ManagementObject queryObj in searcher.Get()) { Console.WriteLine("-----------------------------------"); Console.WriteLine("MSFT_ScheduledTask instance"); Console.WriteLine("-----------------------------------"); Console.WriteLine("State: {0}", queryObj["State"]); Console.WriteLine("TaskName: {0}", queryObj["TaskName"]); } } catch (ManagementException e) { MessageBox.Show("An error occurred while querying for WMI data: " + e.Message); } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)