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

How to update the additional arguments of an existing task?

Topics: Examples
Jun 16, 2016 at 8:41 AM
Within a VB.NET programm i would like to update the additional arguments of an existing task on a remote PC.
Any idea how to perform this?
Thanks for a hint.
Frank
Coordinator
Jun 16, 2016 at 5:54 PM
Edited Jun 20, 2016 at 8:49 PM
This works best if you have initially registered either a single Action or if you have given your action an Id. I'll show both ways:
Using ts As New TaskService("YourRemoteServerName")
   Dim task = ts.RootFolder.Tasks("YourTaskName")
   If task IsNot Nothing
      Dim action As ExecAction = task.Definition.Actions("YourID")
      ' Dim action = task.Definition.Actions(0)
      action.Arguments = "new argument string"
      task.RegisterChanges()
   End If
End Using
Marked as answer by dahall on 6/16/2016 at 9:54 AM
Jun 17, 2016 at 10:12 AM
Hello Dahall,

Thanks for your quick reply.

But when doing so I get the following error:

"TaskDefinition is not a member of task".

I only found
Dim action = task.Definition.Actions[0]

was working.

But then the error is

"Arguments is not a member of ActionCollection"

So I update to your latest version 2.5.20. But still I can't solve this compilation error.

Any idea what can solve this issue? (I had exactly the same error before asking the question :-))

Thanks for a hint.

Frank
Coordinator
Jun 20, 2016 at 8:50 PM
Try edited example. VB is not my primary language so I had some syntax wrong. My apologies.
Jun 21, 2016 at 1:37 PM
Many thanks for the correction. Now it is working. But when running the executable I get the flollowing error:

__"Folder other than the root () was requested on a system only supporting Task Scheduler 1.0."}"__

That is strange. The system is Win7 64 BIT so it should have installed Task Scheduler 2.0.

Any ideas what can now causee this error?

Thanks for an additional hint. Best Regards
Jun 24, 2016 at 1:40 PM
Finally I found the solution. The above error message was a little bit confusing :-).

The tasks we would like to modify were not located in the root folder but in subdirectories.

So the following code is finally working:
Using ts As New TaskService("YourRemoteServerName")
   Dim task = ts.GetFolder("YourSubdirectoryName").Tasks("YourTaskName")
   If task IsNot Nothing
      Dim action As ExecAction = task.Definition.Actions("YourID")
      ' Dim action = task.Definition.Actions(0)
      action.Arguments = "new argument string"
      task.RegisterChanges()
   End If
End Using