Win32_ScheduledJob class
Applies to: desktop apps only
The Win32_ScheduledJob WMI 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.
Windows 2000 and Windows NT 4.0: You can use the Scheduled Tasks UI to modify the task you originally created with WMI. However, although the task is successfully modified, you can no longer access the task using WMI.
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
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.
| 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
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.
Value Meaning - 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.
Value Meaning - 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. On Windows 2000, tasks started through Win32_ScheduledJob run under the LocalSystem account. However, in Windows XP with Service Pack 1 (SP1) and Windows Server 2003, such tasks run under the NetworkServiceHost Account. You must be a member of the administrators group to create a scheduled job using this class.
Using Windows 2000 if you start a task remotely, the task starts as an interactive, desktop task. Using Windows XP with SP1 and Windows Server 2003, the task is not interactive. To prevent the remote process that Win32_ScheduledJob starts from running interactively under LocalSystem in Windows 2000, you can change the default account in Control Panel.
The following procedure describes how to change the default account in Windows 2000.
To change the default account in Windows 2000
- In Control Panel, double-click Scheduled Tasks.
- In the Scheduled Tasks dialog box, select the scheduled task.
- From the Advanced menu, select AT Service Account.
- Select the account for the task that you want to run.
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 2000 Professional |
|---|---|
|
Minimum supported server | Windows 2000 Server |
|
Namespace |
\root\CIMV2 |
|
MOF |
|
|
DLL |
|
See also
Send comments about this topic to Microsoft
Build date: 3/9/2012
- 3/15/2012
- Script_n_Me
The "RunRepeatedly " should set to TRUE that is obviously. But in which parameter you set the 15 minutes interval for example?
- 5/3/2011
- Cosmin
- 2/3/2011
- chsar
- 9/1/2009
- Joe-Cissec Corp
- 8/24/2009
- Venugopala Rao Moram
Script run "notepad.exe" after 2 minutes in WinXP SP1 it works well and I can see "notepad" on my desktop, but it don't appears in Vista Basic (process "notepad.exe" is exists)
That I do not so?
t=DateAdd("n",2,time)
min=Minute(t)
hou=Hour(t)
if Len(min)=1 then min="0"&min
if Len(hou)=1 then hou="0"&hou
CreateObject("WbemScripting.SWbemLocator").ConnectServer.get("Win32_ScheduledJob").create "notepad.exe","********"&hou&min&"00.000000+180",1,"","",1
- 9/23/2008
- Momon
I check it on Vista and doesn't return anything.
- 5/5/2008
- pcatalina
"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."
Fair enough, but:
-Is there any class that does "represent a job created with the Scheduled Task Wizard from the Control Panel." I want to discover the jobs, if not modify them.
-Is it possible to at least view "a task created by WMI in the Scheduled Tasks UI."?
I don't want to appear critical, but I can't believe that this has been overlooked...
- 10/5/2007
- oldbie
This appears to be incorrect as ********123000.000000-420 would obviously be 12:30pm PDT... it should read
"For example: "********123000.000000-420" specifies 12.30 (12:30 P.M.) PST with daylight savings time in effect."
or
"For example: "********143000.000000-420" specifies 14.30 (2:30 P.M.) PST with daylight savings time in effect."
This may be obvious to some, but it threw me off thinking that the time was stored as Zulu with having to use the offset to determine actual time. This doesn't appear to be the case, the time given IS local time with the offset allowing you to calculate zulu time.
- 8/21/2007
- Michael Letterle
- 8/13/2007
- Marcelo MaFra
- 8/2/2007
- Ian_Add
Yes, using the example above, your syntax will be:
objNewJob.Create ("cmd /c cscript c:\scriptname.vbs", "********012500.000000-420", True , 4, , True, JobId)
- 3/19/2007
- nosuchuser
Can we run .vbs files using Win32_ScheduledJob? How?
Help!!!
- 3/8/2007
- forshashank