Win32_ScheduledJob class
The Win32_ScheduledJob WMI class represents a job created with the AT command.
Note
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. For more information, see the Remarks section.
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
[Dynamic, Provider("CIMWin32"), UUID("{8502C4E0-5FBB-11D2-AAC1-006008C78BC7}"), SupportsCreate, CreateBy("Create"), SupportsDelete, DeleteBy("Delete"), AMENDMENT]
class Win32_ScheduledJob : CIM_Job
{
string Caption;
string Description;
datetime InstallDate;
string Name;
string Status;
datetime ElapsedTime;
string Notify;
string Owner;
uint32 Priority;
datetime TimeSubmitted;
datetime UntilTime;
string Command;
uint32 DaysOfMonth;
uint32 DaysOfWeek;
boolean InteractWithDesktop;
uint32 JobId;
string JobStatus;
boolean RunRepeatedly;
datetime StartTime;
};
Members
The Win32_ScheduledJob class has these types of members:
Methods
The Win32_ScheduledJob class has these methods.
Method | Description |
---|---|
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
-
Qualifiers: MaxLen (64), DisplayName ("Caption")
A short textual description of the object.
This property is inherited from CIM_ManagedSystemElement.
-
-
Command
-
-
Data type: string
-
Access type: Read-only
-
Qualifiers: MappingStrings ("Win32API|Network Management Structures|AT_INFO|Command")
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
-
Qualifiers: MappingStrings ("Win32API|Network Management Structures|AT_INFO|DaysOfMonth")
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.
-
-
1 (1)
-
1st
-
2 (2)
-
2nd
-
3 (4)
-
3rd
-
4 (8)
-
4th
-
5 (16)
-
5th
-
6 (32)
-
6th
-
7 (64)
-
7th
-
8 (128)
-
8th
-
9 (256)
-
9th
-
10 (512)
-
10th
-
11 (1024)
-
11th
-
12 (2048)
-
12th
-
13 (4096)
-
13th
-
14 (8192)
-
14th
-
15 (16384)
-
15th
-
16 (32768)
-
16th
-
17 (65536)
-
17th
-
18 (131072)
-
18th
-
19 (262144)
-
19th
-
20 (524288)
-
20th
-
21 (1048576)
-
21st
-
22 (2097152)
-
22nd
-
23 (4194304)
-
23rd
-
24 (8388608)
-
24th
-
25 (16777216)
-
25th
-
26 (33554432)
-
26th
-
27 (67108864)
-
27th
-
28 (134217728)
-
28th
-
29 (268435456)
-
29th
-
30 (536870912)
-
30th
-
31 (1073741824)
-
31st
DaysOfWeek
-
Data type: uint32
-
Access type: Read-only
-
Qualifiers: MappingStrings ("Win32API|Network Management Structures|AT_INFO|DaysOfWeek")
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.
Monday (1)
Tuesday (2)
Wednesday (4)
Thursday (8)
Friday (16)
Saturday (32)
Sunday (64)
Description
-
Data type: string
-
Access type: Read-only
-
Qualifiers: DisplayName ("Description")
A textual description of the object.
This property is inherited from CIM_ManagedSystemElement.
ElapsedTime
-
Data type: datetime
-
Access type: Read-only
Length of time the job has been executing.
This property is inherited from CIM_Job.
InstallDate
-
Data type: datetime
-
Access type: Read-only
-
Qualifiers: MappingStrings ("MIF.DMTF|ComponentID|001.5"), DisplayName ("Install Date")
Indicates when the object was installed. Lack of a value does not indicate that the object is not installed.
This property is inherited from CIM_ManagedSystemElement.
InteractWithDesktop
-
Data type: boolean
-
Access type: Read-only
-
Qualifiers: MappingStrings ("Win32API|Network Management Structures|AT_INFO|Flags|JOB_NONINTERACTIVE")
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, MappingStrings ("Win32API|Network Management Structures|AT_ENUM|JobId")
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
-
Qualifiers: Override ("JobStatus"), MappingStrings ("Win32API|Network Management Structures|AT_ENUM|Flags|JOB_EXEC_ERROR")
Status of execution the last time this job was scheduled to run.
Success ("Success")
Failure ("Failure")
Name
-
Data type: string
-
Access type: Read-only
-
Qualifiers: DisplayName ("Name")
Label by which the object is known. When subclassed, this property can be overridden to be a key property.
This property is inherited from CIM_ManagedSystemElement.
Notify
-
Data type: string
-
Access type: Read-only
User is notified upon job completion or failure.
This property is inherited from CIM_Job.
Owner
-
Data type: string
-
Access type: Read-only
User who submitted the job.
This property is inherited from CIM_Job.
Priority
-
Data type: uint32
-
Access type: Read-only
Importance of a job's execution.
This property is inherited from CIM_Job.
RunRepeatedly
-
Data type: boolean
-
Access type: Read-only
-
Qualifiers: MappingStrings ("Win32API|Network Management Structures|AT_INFO|Flags|JOB_RUN_PERIODICALLY")
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
-
Qualifiers: Override ("StartTime"), MappingStrings ("Win32API|Network Management Structures|AT_ENUM|JobTime")
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
-
Qualifiers: MaxLen (10), DisplayName ("Status")
String that indicates the current status of the object. Operational and non-operational status can be defined. Operational status can include "OK", "Degraded", and "Pred Fail". "Pred Fail" indicates that an element is functioning properly, but is predicting a failure (for example, a SMART-enabled hard disk drive).
Non-operational status can include "Error", "Starting", "Stopping", and "Service". "Service" can apply during disk mirror-resilvering, reloading a user permissions list, or other administrative work. Not all such work is online, but the managed element is neither "OK" nor in one of the other states.
This property is inherited from CIM_ManagedSystemElement.
Values include the following:
OK ("OK")
Error ("Error")
Degraded ("Degraded")
Unknown ("Unknown")
Pred Fail ("Pred Fail")
Starting ("Starting")
Stopping ("Stopping")
Service ("Service")
Stressed ("Stressed")
NonRecover ("NonRecover")
No Contact ("No Contact")
Lost Comm ("Lost Comm")
TimeSubmitted
-
Data type: datetime
-
Access type: Read-only
Time that the job was submitted.
This property is inherited from CIM_Job.
UntilTime
-
Data type: datetime
-
Access type: Read-only
Time at which the job is invalid or should be stopped.
This property is inherited from CIM_Job.
Remarks
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 Win32_ScheduledJob class is derived from CIM_Job. 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.
Because Win32_ScheduledJob is based on the NetScheduleJobGetInfo Win32 API, you cannot use this class in conjunction with the Task Scheduler. If you wish to use Task Scheduler, use the Task Scheduler API. For more information, see the Task Scheduler Reference.
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
Requirement | Value |
---|---|
Minimum supported client |
Windows Vista |
Minimum supported server |
Windows Server 2008 |
Namespace |
Root\CIMV2 |
MOF |
|
DLL |
|
See also