C# - How to list Scheduled Tasks for a specific user with the TaskSchedular Class

前端 未结 3 1422
半阙折子戏
半阙折子戏 2021-01-14 03:31

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.co

3条回答
  •  无人共我
    2021-01-14 04:32

    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);
            }
        }
    }
    

提交回复
热议问题