This project has moved. For the latest updates, please go here.

Checking if Task Exists

May 29, 2014 at 6:00 PM
Edited May 29, 2014 at 6:01 PM
I have the following function in my program to check if a task exists or not.
Function doesTaskExist(ByVal nameOfTask As String, ByRef taskObject As Task) As Boolean
    Using taskServiceObject As TaskService = New TaskService()
        taskObject = taskServiceObject.GetTask(nameOfTask)

        If taskObject Is Nothing Then
            Return False
        Else
            Return True
        End If
    End Using
End Function
I use this function to return an instance of the task object to work on the task such as executing it from inside a program.
Dim task As Microsoft.Win32.TaskScheduler.Task
If doesTaskExist("My Task", task) = True Then
    task.Run()
End If
OK, this code works fine if the "When running the task, use the following user account" portion of the task in Task Scheduler (the Microsoft provided interface) matches that of the user that's running the program that's checking the existence of the task. (Does that statement make sense?)

But, as soon as I change the task's "When running the task, use the following user account" portion of the task in Task Scheduler to say... "BUILTIN\Administrators", that function doesn't say that the task exists.

I need to create a task that will be owned by every Administrator on the computer and able to be run by any administrator on that machine. Again, does that makes any sense?
Coordinator
May 30, 2014 at 4:29 PM
You are likely experiencing the joys of UAC. When running C#, by default, it runs at reduced privileges. What happens if you run your code "as Administrator"?
May 30, 2014 at 5:37 PM
Even with Administrator privileges/rights, it shows that the task doesn't exist. I'm beginning to think that tasks created by another user are invisible to users that didn't create it (at least to this API).