Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Windows Scheduled Tasks Automatically Using VB

Status
Not open for further replies.

BenSC

Technical User
Jul 24, 2001
43
GB
Dear All,
My Goal is to create a form where users can specify their scheduling requirements in various fields and then click a button, which will create the windows scheduled task for them to minimise user involvement.
I've searched around and can't seem to find any sample VB code to work from as the Microsoft reference is all in C++.

If anyone has done something similar and could point me in the right direction on this I would be very grateful.

Many Thanks
Ben Cooper
 
Of course. My NetScheduleJobAdd code in thread222-794484 should be most of what you are looking for. Although you may want to update the Enum I created with:
Code:
[blue]
Private Enum JobAdd
    JOB_RUN_PERIODICALLY = &H1  ' If you set this flag, the job runs, and continues to run, on each
                                ' day for which a corresponding bit is set in the DaysOfMonth or
                                ' DaysOfWeek member. The job is not deleted after it executes.
                                ' If this flag is clear, the job runs only once for each bit set in
                                ' these members. The job is deleted after it executes once.
                         
    JOB_ADD_CURRENT_DATE = &H8  ' If you set this flag, the job executes at the first occurrence of
                                ' JobTime at the computer where the job is queued.
                                ' Setting this flag is equivalent to setting the bit for the current
                                ' day in the DaysOfMonth member.
    JOB_NONINTERACTIVE = &H10
End Enum
[/blue]
 
You could also program the AT command.

The AT command schedules commands and programs to run on a computer at
a specified time and date. The Schedule service must be running to use
the AT command.

AT [\\computername] [ [id] [/DELETE] | /DELETE [/YES]]
AT [\\computername] time [/INTERACTIVE]
[ /EVERY:date[,...] | /NEXT:date[,...]] "command"

\\computername Specifies a remote computer. Commands are scheduled on the
local computer if this parameter is omitted.
id Is an identification number assigned to a scheduled
command.
/delete Cancels a scheduled command. If id is omitted, all the
scheduled commands on the computer are canceled.
/yes Used with cancel all jobs command when no further
confirmation is desired.
time Specifies the time when command is to run.
/interactive Allows the job to interact with the desktop of the user
who is logged on at the time the job runs.
/every:date[,...] Runs the command on each specified day(s) of the week or
month. If date is omitted, the current day of the month
is assumed.
/next:date[,...] Runs the specified command on the next occurrence of the
day (for example, next Thursday). If date is omitted, the
current day of the month is assumed.
"command" Is the Windows NT command, or batch program to be run.

-David
2006 Microsoft Valueable Professional (MVP)
2006 Dell Certified System Professional (CSP)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top