Win32_ScheduledJob class

The Win32_ScheduledJobWMI class represents a job created with the AT command. The Win32_ScheduledJob class does not represent a job created with the Scheduled Task Wizard from the Control Panel. You cannot change a task created by WMI in the Scheduled Tasks UI.

Each job scheduled against the schedule service is stored persistently (the scheduler can start a job after a reboot), and is executed at the specified time and day of the week or month. If the computer is not active, or if the scheduled service is not running at the specified job time, the schedule service runs the specified job on the next day at the specified time.

Jobs are scheduled according to Coordinated Universal Time (UTC) with bias offset from Greenwich Mean Time (GMT), which means that a job can be specified using any time zone. The Win32_ScheduledJob class returns the local time with UTC offset when enumerating an object, and converts to local time when creating new jobs. For example, a job specified to run on a computer in Boston at 10:30 P.M. Monday PST time will be scheduled to run locally at 1:30 A.M. Tuesday EST.

Note  A client must take into account whether or not daylight savings time is in operation on the local computer, and if it is, then subtract a bias of 60 minutes from the UTC offset.

The following syntax is simplified from Managed Object Format (MOF) code and includes all of the inherited properties. Properties and methods are in alphabetic order, not MOF order.

Syntax

[Provider("CIMWin32")]class Win32_ScheduledJob : CIM_Job
{
  string   Caption;
  string   Command;
  uint32   DaysOfMonth;
  uint32   DaysOfWeek;
  string   Description;
  datetime ElapsedTime;
  datetime InstallDate;
  boolean  InteractWithDesktop;
  uint32   JobId;
  string   JobStatus;
  string   Name;
  string   Notify;
  string   Owner;
  uint32   Priority;
  boolean  RunRepeatedly;
  datetime StartTime;
  string   Status;
  datetime TimeSubmitted;
  datetime UntilTime;
};

Members

The Win32_ScheduledJob class has these types of members:

Methods

The Win32_ScheduledJob class has these methods.

MethodDescription
Create

Class method that submits a job to the operating system for execution at a specified future time and date.

Delete

Class method that deletes a scheduled job.

 

Properties

The Win32_ScheduledJob class has these properties.

Caption
Data type: string
Access type: Read-only

Short description of the object—a one-line string.

Command
Data type: string
Access type: Read-only

Name of the command, batch program, or binary file (and command-line arguments) that the schedule service uses to invoke the job.

Example: "defrag /q/f"

DaysOfMonth
Data type: uint32
Access type: Read-only

Days of the month when the job is scheduled to run. If a job is scheduled to run on multiple days of the month, these values can be joined in a logical OR. For example, if a job is to run on the 1st and 16th of each month, the value of the DaysOfMonth property would be 1 OR 32768.

ValueMeaning
1 (0x1)

1st

2 (0x2)

2nd

4 (0x4)

3rd

8 (0x8)

4th

16 (0x10)

5th

32 (0x20)

6th

64 (0x40)

7th

128 (0x80)

8th

256 (0x100)

9th

512 (0x200)

10th

1024 (0x400)

11th

2048 (0x800)

12th

4096 (0x1000)

13th

8192 (0x2000)

14th

16384 (0x4000)

15th

32768 (0x8000)

16th

65536 (0x10000)

17th

131072 (0x20000)

18th

262144 (0x40000)

19th

524288 (0x80000)

20th

1048576 (0x100000)

21st

2097152 (0x200000)

22nd

4194304 (0x400000)

23rd

8388608 (0x800000)

24th

16777216 (0x1000000)

25th

33554432 (0x2000000)

26th

67108864 (0x4000000)

27th

134217728 (0x8000000)

28th

268435456 (0x10000000)

29th

536870912 (0x20000000)

30th

1073741824 (0x40000000)

31st

 

DaysOfWeek
Data type: uint32
Access type: Read-only

Days of the week when a job is scheduled to run. If a job is scheduled to run on multiple days of the week, the values can be joined in a logical OR. For example, if a job is scheduled to run on Mondays, Wednesdays, and Fridays the value of the DaysOfWeek property would be 1 OR 4 OR 16.

ValueMeaning
1 (0x1)

Monday

2 (0x2)

Tuesday

4 (0x4)

Wednesday

8 (0x8)

Thursday

16 (0x10)

Friday

32 (0x20)

Saturday

64 (0x40)

Sunday

 

Description
Data type: string
Access type: Read-only

Description of the object.

ElapsedTime
Data type: datetime
Access type: Read-only

Length of time that the job has been executing.

InstallDate
Data type: datetime
Access type: Read-only

Object was installed. This property does not need a value to indicate that the object is installed.

InteractWithDesktop
Data type: boolean
Access type: Read-only

Specified job is interactive, which means that a user can give input to a scheduled job while it is executing.

JobId
Data type: uint32
Access type: Read-only
Qualifiers: Key

Identifying number of the job. It is used by methods as a handle to one job being scheduled on this computer.

JobStatus
Data type: string
Access type: Read-only

Status of execution the last time this job was scheduled to run.

The values are:

"Success"

"Failure"

Name
Data type: string
Access type: Read-only

Label by which the object is known. When subclassed, the property can be overridden to be a key property.

Notify
Data type: string
Access type: Read-only

User to be notified when the job completes or fails.

Owner
Data type: string
Access type: Read-only

User that submitted the job.

Priority
Data type: uint32
Access type: Read-only

Urgency or importance of execution of a job.

RunRepeatedly
Data type: boolean
Access type: Read-only

Scheduled job runs repeatedly on the days that the job is scheduled. If False, then the job is run one time.

StartTime
Data type: datetime
Access type: Read-only

UTC time to run the job, in the form of "YYYYMMDDHHMMSS.MMMMMM(+-)OOO", where "YYYYMMDD" must be replaced by "********". The replacement is necessary because the scheduling service only allows jobs to be configured to run one time, or run on a day of the month or week. A job cannot be run on a specific date.

The "(+-)OOO" section of the StartTime property value is the current bias for local time translation. The bias is the difference between the UTC time and local time. To calculate the bias for your time zone, multiply the number of hours that your time zone is ahead or behind Greenwich Mean Time (GMT) by 60 (use a positive number for the number of hours if your time zone is ahead of GMT and a negative number if your time zone is behind GMT). Add an additional 60 to your calculation if your time zone is using daylight savings time. For example, the Pacific Standard Time zone is eight hours behind GMT, therefore the bias is equals to -420 (-8 * 60 + 60) when daylight savings time is in use and -480 (-8 * 60) when daylight savings time is not in use. You can also determine the value of the bias by querying the bias property of the Win32_TimeZone class.

For example: "********123000.000000-420" specifies 14.30 (2:30 P.M.) PST with daylight savings time in effect.

Status
Data type: string
Access type: Read-only

Current status of the object. Various operational and nonoperational statuses can be defined. Operational statuses include: "OK", "Degraded", and "Pred Fail" (an element, such as a SMART-enabled hard disk drive, may be functioning properly but predicting a failure in the near future). Nonoperational statuses include: "Error", "Starting", "Stopping", and "Service". The latter, "Service", could apply during mirror-resilvering of a disk, reload of a user permissions list, or other administrative work. Not all such work is online, yet the managed element is neither "OK" nor in one of the other states.

The values are:

"OK"
"Error"
"Degraded"
"Unknown"
"Pred Fail"
"Starting"
"Stopping"
"Service"
TimeSubmitted
Data type: datetime
Access type: Read-only

Time the job is submitted.

UntilTime
Data type: datetime
Access type: Read-only

Time after which the job is invalid or must be stopped.

Remarks

The Win32_ScheduledJob class is derived from CIM_Job. In Windows XP with Service Pack 1 (SP1) and Windows Server 2003, tasks started through Win32_ScheduledJob run under the NetworkServiceHost Account. You must be a member of the administrators group to create a scheduled job using this class.

The Win32_ScheduledJob class is internally using the AT protocol, which is bound to deprecation starting with Windows 8 and Windows Server 2012. As a first step the AT protocol is disabled by default. If the protocol is disabled, for example calling the Create method on a Win32_ScheduledJob object will fail with error 0x8. You can turn the AT protocol back on by adding the following registry entry:

Key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\Configuration 
Name: EnableAt 
Type: REG_DWORD
Value: 1

You may need to restart the machine to make the setting effective.

Examples

For script code examples, see WMI Tasks for Scripts and Applications and the TechNet ScriptCenter Script Repository.

For C++ code examples, see WMI C++ Application Examples.

The following VBScript code example schedules Notepad.exe to run interactively at 1:25 by the local computer time every Wednesday.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")
Set objNewJob = objWMIService.Get("Win32_ScheduledJob")
errJobCreated = objNewJob.Create _
    ("Notepad.exe", "********012500.000000-420", _
        True , 4, , True, JobId) 
If errJobCreated <> 0 Then
Wscript.Echo "Error on task creation"
Else
Wscript.Echo "Task created"
End If

Requirements

Minimum supported client

Windows XP

Minimum supported server

Windows Server 2003

Namespace

\root\CIMV2

MOF

CIMWin32.mof

DLL

CIMWin32.dll

See also

Operating System Classes

 

 

Show:
© 2014 Microsoft. All rights reserved.