C#中 - 如何列出计划任务为与TaskSchedular类特定用户 [英] C# - How to list Scheduled Tasks for a specific user with the TaskSchedular Class

查看:249
本文介绍了C#中 - 如何列出计划任务为与TaskSchedular类特定用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在想,如果有人可以帮助我,我想列出特定用户(管理员)计划任务使用的TaskScheduler类(HTTP在本地计算机上://www.$c$cproject.com/KB/ CS / tsnewlib.aspx)我有以下几点:

I was wondering if someone could help me, I am trying to list Scheduled Tasks from a specific user (Admin) on the local computer using the TaskScheduler Class (http://www.codeproject.com/KB/cs/tsnewlib.aspx) I have the following:

    // richTextBox6.Text = string.Join(Environment.NewLine, taskNames);
    private void button22_Click(object sender, EventArgs e)
    {
        listBox1.Items.Clear();
        string machineName = (@"\\" + System.Environment.MachineName);
        ScheduledTasks st = new ScheduledTasks(machineName);
        // Get an array of all the task names
        string[] taskNames = st.GetTaskNames();
        foreach (var taskName in taskNames)
        {
            listBox1.Items.Add(taskName);
        }

        st.Dispose();
    }

@\指定本地机器是目标,但有可能将用户添加到这个? (由于只列出任务是在C:\ WINDOWS \任务执行时)

"@"\"" Specifies that the local machine is the target, but is it possible to add a user to this? (Since it only lists tasks that are in C:\Windows\Tasks when executed)

推荐答案

目前似乎没有一种方式进行查询(仅限一台机器的名称)时指定一个用户名,但可以使用筛选结果自己在造物主属性:

There doesn't seem to be a way to specify a user name when performing the query (only a machine name), but you can filter the results yourself using the Creator property:

foreach (string taskName in st.GetTaskNames()) {
    using (Task task = st.OpenTask(taskName)) {
        if (task.Creator == "username") {
            listBox1.Items.Add(taskName);
        }
    }
}

这篇关于C#中 - 如何列出计划任务为与TaskSchedular类特定用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆