Create method
Collapse the table of content
Expand the table of content

Create method of the Win32_ScheduledJob class

The CreateWMI 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.

Use the following values to set the bit:Meaning
1 (0x1)

Monday

2 (0x2)

Tuesday

4 (0x4)

Wednesday

8 (0x8)

Thursday

16 (0x10)

Friday

32 (0x20)

Saturday

64 (0x40)

Sunday

 

DaysOfMonth [in, optional]

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

Use the following values to set the bit:Meaning
1 (0x1)

Day 1 of a month

2 (0x2)

Day 2 of a month

4 (0x4)

Day 3 of a month

8 (0x8)

Day 4 of a month

16 (0x10)

Day 5 of a month

32 (0x20)

Day 6 of a month

64 (0x40)

Day 7 of a month

128 (0x80)

Day 8 of a month

256 (0x100)

Day 9 of a month

512 (0x200)

Day 10 of a month

1024 (0x400)

Day 11 of a month

2048 (0x800)

Day 12 of a month

4096 (0x1000)

Day 13 of a month

8192 (0x2000)

Day 14 of a month

16364 (0x3FEC)

Day 15 of a month

32768 (0x8000)

Day 16 of a month

65536 (0x10000)

Day 17 of a month

131072 (0x20000)

Day 18 of a month

262144 (0x40000)

Day 19 of a month

524288 (0x80000)

Day 20 of a month

1048576 (0x100000)

Day 21 of a month

2097152 (0x200000)

Day 22 of a month

4194304 (0x400000)

Day 23 of a month

8388608 (0x800000)

Day 24 of a month

16777216 (0x1000000)

Day 25 of a month

33554432 (0x2000000)

Day 26 of a month

67108864 (0x4000000)

Day 27 of a month

134217728 (0x8000000)

Day 28 of a month

268435456 (0x10000000)

Day 29 of a month

536870912 (0x20000000)

Day 30 of a month

1073741824 (0x40000000)

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.

Return code/valueDescription
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

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

 

 

Show:
© 2016 Microsoft