C# - 使ManagementObjectSearcher输出到TextBox

时间:2011-06-20 21:05:37

标签: c# .net windows

我有以下代码来抓取计划任务,虽​​然我无法将它们输出到文本框中:

private void button22_Click(object sender, EventArgs e)
{
    var query = new ManagementObjectSearcher("SELECT * FROM Win32_ScheduledJob");
    var tasks = query.Get();
    richTextBox6.Text = ManagementObjectSearcher.ToString();
}

2 个答案:

答案 0 :(得分:2)

试试这个

        var query = new ManagementObjectSearcher("SELECT * FROM Win32_ScheduledJob");
        var tasks = query.Get();
        foreach (ManagementObject task in tasks)
        {
            richTextBox6.Text += Environment.NewLine + task["Description"]
        }

答案 1 :(得分:0)

foreach (ManagementObject task in tasks)
{
      Console.WriteLine(task.GetPropertyValue("Description"));
}

here获取属性