Click here to Skip to main content
13,251,998 members (61,344 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


4 bookmarked
Posted 30 Aug 2013

Schedule task in Windows 7 with VB.NET

, 30 Aug 2013
Rate this:
Please Sign up or sign in to vote.
Schedule task in windows 7


Whenever we schedule a task in Windows we always use itaskscheduler or taskScheduler as we can get its DLL or library very easily in our Windows system in C:\Windows\System32\ drive as taskschd.dll. But this time it is something different.

The library of the task scheduler was used till Vista [Windows Taskscheduler 1.0] now when we work in upgraded versions of windows a new wrapper class has been launched by Windows as itaskservice which helps programmers to work with the Windows Taskscheduler 2.0.

This wrapper class needs an external DLL called Microsoft.Win32.TaskScheduler.


I developed this code in Visual studio 2012 so you will need the same. You can download the .dll from the following link also:

As a reference of this task you can take a reference of's link:

Using the code 

Imports Microsoft.Win32.TaskScheduler
Imports System.IO

Public Class Form1
    Public Shared Function ScheduleTaskInWin_TaskScheduler(
                                                          ByRef sunday As String, _
                                                          ByRef monday As String, _
                                                          ByRef tues As String, _
                                                          ByRef wedn As String, _
                                                          ByRef thursday As String, _
                                                          ByRef friday As String, _
                                                          ByRef saturday As String
        Using ts As New TaskService()
        ' Create a new task definition and assign properties
            Dim td As TaskDefinition = ts.NewTask
            td.RegistrationInfo.Description = _
              "Any description which you want to give for you task. "
           ' use below mentioned code for WeeklyTrigger 
            Dim wt As New WeeklyTrigger()
            wt.StartBoundary = DateTime.Today.AddDays(0)
            wt.DaysOfWeek = sunday Or monday Or tues Or wedn Or thursday Or friday Or saturday
            wt.Repetition.Duration = TimeSpan.FromHours(24)
            wt.Repetition.Interval = TimeSpan.FromDays(1)

           ' use below mentioned code whin you want to create
           ' dailytrigger as in a way in each our after 1 hour

            'Dim dt As New DailyTrigger()
            'dt.DaysInterval = 1
            'dt.StartBoundary = DateTime.Today.AddDays(0)
            'dt.Repetition.Duration = TimeSpan.FromDays(30)
            'dt.Repetition.Interval = TimeSpan.FromMinutes(60)


   Dim FolderPath As String = AppDomain.CurrentDomain.BaseDirectory
            Dim ExeLocation As String = Path.Combine(FolderPath, "nameOfExe.exe")
            ExeLocation = ExeLocation.Replace("\"c, "/"c)
            ' Add an action (shorthand) that runs Notepad
            td.Actions.Add(New ExecAction(ExeLocation, "c:\nameOfLogFile.log"))
            ' Register the task in the root folder
            ts.RootFolder.RegisterTaskDefinition("NameOfScheduleTask", td)
        End Using

        Return ""
    End Function

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Dim sunday As String = DaysOfTheWeek.Sunday
        Dim monday As String = DaysOfTheWeek.Monday
        Dim tuesday As String = DaysOfTheWeek.Tuesday
        Dim Wednesday As String = DaysOfTheWeek.Wednesday
        Dim Thursday As String = DaysOfTheWeek.Thursday
        Dim Friday As String = DaysOfTheWeek.Friday
        Dim Saturday As String = DaysOfTheWeek.Saturday

        ScheduleTaskInWin_TaskScheduler(sunday, monday, _
                 tuesday, Wednesday, Thursday, Friday, Saturday)
    End Sub
End Class

Points of Interest

You can see you created task in same C:\windows\Tasks location and your scheduled task in task scheduler.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

_Niharika Saxena
Web Developer
India India
No Biography provided

You may also be interested in...

Comments and Discussions

Questiondll code not reachable Pin
Cool Smith2-Aug-17 12:53
memberCool Smith2-Aug-17 12:53 
Questionthank you for your code Pin
michael azzar11-Jun-16 15:32
membermichael azzar11-Jun-16 15:32 
SuggestionHyperlink to library Pin
David Hall26-Sep-14 6:03
memberDavid Hall26-Sep-14 6:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171114.1 | Last Updated 30 Aug 2013
Article Copyright 2013 by _Niharika Saxena
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid