Rediger

Del via


Create method of the Win32_ScheduledJob class

The Create WMI class method submits a job to an operating system for execution at a specified time and date in the future. This method requires that the schedule service be started on the computer to which the job is submitted.

This topic uses Managed Object Format (MOF) syntax. For more information about using this method, see Calling a Method.

Syntax

uint32 Create(
  [in]           string   Command,
  [in]           datetime StartTime,
  [in, optional] boolean  RunRepeatedly,
  [in, optional] uint32   DaysOfWeek,
  [in, optional] uint32   DaysOfMonth,
  [in, optional] boolean  InteractWithDesktop,
  [out]          uint32   JobId
);

Parameters

Command [in]

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

Example: "defrag /q /f".

StartTime [in]

Coordinated Universal Time (UTC) time to run a job. The form must be: "YYYYMMDDHHMMSS.MMMMMM(+-)OOO", where "YYYYMMDD" must be replaced by "********". For example: "********143000.000000-420" specifies 14.30 (2:30 P.M.) PST with daylight savings time in effect.

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 the 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.

RunRepeatedly [in, optional]

If True, a scheduled job runs repeatedly on specific days. The default is False.

DaysOfWeek [in, optional]

Days of the week when a job is scheduled to run; used only when the RunRepeatedly parameter is True. To schedule a job for more than one day of the week, join the appropriate values in a logical OR. For example, to schedule a job for Tuesdays and Fridays, the value of DaysOfWeek are 2 OR 16.

Monday (1)

Tuesday (2)

Wednesday (4)

Thursday (8)

Friday (16)

Saturday (32)

Sunday (64)

DaysOfMonth [in, optional]

Days of the month when a job is scheduled to run; used only when the RunRepeatedly parameter is True.

1 (1)

Day 1 of a month

2 (2)

Day 2 of a month

3 (4)

Day 3 of a month

4 (8)

Day 4 of a month

5 (16)

Day 5 of a month

6 (32)

Day 6 of a month

7 (64)

Day 7 of a month

8 (128)

Day 8 of a month

9 (256)

Day 9 of a month

10 (512)

Day 10 of a month

11 (1024)

Day 11 of a month

12 (2048)

Day 12 of a month

13 (4096)

Day 13 of a month

14 (8192)

Day 14 of a month

15 (16384)

Day 15 of a month

16 (32768)

Day 16 of a month

17 (65536)

Day 17 of a month

18 (131072)

Day 18 of a month

19 (262144)

Day 19 of a month

20 (524288)

Day 20 of a month

21 (1048576)

Day 21 of a month

22 (2097152)

Day 22 of a month

23 (4194304)

Day 23 of a month

24 (8388608)

Day 24 of a month

25 (16777216)

Day 25 of a month

26 (33554432)

Day 26 of a month

27 (67108864)

Day 27 of a month

28 (134217728)

Day 28 of a month

29 (268435456)

Day 29 of a month

30 (536870912)

Day 30 of a month

31 (1073741824)

Day 31 of a month

InteractWithDesktop [in, optional]

If True, the specified job should be interactive, which means that a user can give input to a scheduled job while the job is executing. The default is False.

JobId [out]

Identifier number of a job. This parameter is a handle to a job being scheduled on a computer.

Return value

Returns a value of 0 (zero) when successful, and a different number to indicate an error. For additional error codes, see WMI Error Constants or WbemErrorEnum. For general HRESULT values, see System Error Codes.

Successful completion

0

The request is accepted.

Not supported

1

The request is not supported.

Access denied

2

The user does not have the necessary access.

Unknown failure

8

Interactive process.

Path not found

9

The directory path to the service executable file cannot be found.

Invalid parameter

21

Invalid parameters have been passed to the service.

Service not started

22

The account that this service runs under is invalid or lacks the permissions to run the service.

Other

23 4294967295

Remarks

If your scheduled job starts an interactive program such as Notepad, then the InteractWithDeskto property must be set to True or the program's screen is not visible. The process still appears in the Task Manager even if it does not appear on the screen.

Requirements

Requirement Value
Minimum supported client
Windows Vista
Minimum supported server
Windows Server 2008
Namespace
Root\CIMV2
MOF
CIMWin32.mof
DLL
CIMWin32.dll

See also

Operating System Classes

Win32_ScheduledJob