I have the following function in my program to check if a task exists or not.
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?
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?