That error usually means that the TaskDefinition.Principle.UserId or the userId parameter of the RegisterTaskDefinition has been supplied an invalid user account name.
To answer the second question:
To answer the second question:
Using TS As New TaskService()
If TS.FindTask("MyTaskNameHere") = Nothing Then
' You don't have that task
End If
End Using