Search code examples
vb.netscheduled-taskswindows-server

Task schedule in windows server from other computer


I am scheduling a task from vb.net with these parameters. Generates the task correctly and executes it. This works correctly in local, but I need that task to be created on the server. Any ideas?

Using tService As New TaskService()
    Dim Fecha As DateTime = DateTime.Parse(txtFDesde.Text + " " + txtHDesde.Text)
    Dim tTime As New TimeTrigger()
    Dim tDefinition As TaskDefinition = tService.NewTask
    tDefinition.RegistrationInfo.Description = "Tarea programada para ejecutar"
    tDefinition.Settings.RunOnlyIfLoggedOn = False
    tTime.StartBoundary = New DateTime(Fecha.Year, Fecha.Month, Fecha.Day, Fecha.Hour, Fecha.Minute, 0)
    tDefinition.Triggers.Add(tTime)
    Dim url As String = "http://localhost:5000/" & Param
    tDefinition.Actions.Add(New ExecAction("cmd.exe", "/c start " & url))
    tService.RootFolder.RegisterTaskDefinition("Test " & Param, tDefinition)
End Using

Solution

  • Try the static connect method...you'll need credentials to the server....https://msdn.microsoft.com/en-us/library/windows/desktop/aa383451(v=vs.85).aspx