Solved

vb.net scheduled task window

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

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now