Solved

vb.net scheduled task window

Posted on 2014-12-23
3
79 Views
Last Modified: 2016-06-23
Hi guys, I'm working with the below code to create a scheduled task and then bring up the properties window of that task. It has no trouble creating the task and loading the properties window, however any changes I make within that properties window is ignored. The code doesn't set a trigger for the task to run, so I click the triggers tab and set a date and time for it to begin, I then OK the window. If I then open up task scheduler and double click on my new task, the triggers tab is empty.  Even if I enter in a description, it doesn't keep it.

Not sure what I'm doing wrong?

Using ts As TaskService = New TaskService
            ' Create a new task definition and assign properties
            Dim td As TaskDefinition = ts.NewTask
            td.RegistrationInfo.Description = "Does something"

            ' Add an action (shorthand) that runs Notepad
            td.Actions.Add(New ExecAction("notepad.exe", "c:\test.log"))

            ' Register the task in the root folder
            ts.RootFolder.RegisterTaskDefinition("Test", td)

            Dim TaskName As String = "Test"

            Dim EditorForm As New TaskEditDialog()
            Dim t As Task
            t = ts.GetTask(TaskName)

            EditorForm.Editable = True
            EditorForm.Initialize(t)
             If EditorForm.ShowDialog = Windows.Forms.DialogResult.Cancel Then
                ts.RootFolder.DeleteTask(TaskName)
            End If
        End Using

Open in new window

0
Comment
Question by:amaru96
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 40514719
have a look at http://emoreau.com/Entries/Articles/2004/08/Interfacing-the-Windows-Task-Scheduler.aspx and more precisely in the comments below the article. There are a few links to free libraries.
0
 
LVL 1

Accepted Solution

by:
amaru96 earned 0 total points
ID: 40515656
Worked it out by adding the below.

 If EditorForm.ShowDialog = Windows.Forms.DialogResult.OK Then
                    ts.RootFolder.RegisterTaskDefinition(TaskName, EditorForm.TaskDefinition)
                Else
                    ts.RootFolder.DeleteTask(TaskName)
                End If

Open in new window

0

Featured Post

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question