Solved

vb.net scheduled task window

Posted on 2014-12-23
3
63 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
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

839 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