WMI Tasks: Scheduled Tasks
WMI scheduled tasks create and get information about scheduled tasks. For other examples, see the TechNet ScriptCenter at https://www.microsoft.com/technet.
The script examples shown in this topic obtain data only from the local computer. For more information about how to use the script to obtain data from remote computers, see Connecting to WMI on a Remote Computer.
The following procedure describes how to run a script.
To run a script
- Copy the code and save it in a file with a .vbs extension, such as filename.vbs. Ensure that your text editor does not add a .txt extension to the file.
- Open a command prompt window and navigate to the directory where you saved the file.
- Type cscript filename.vbs at the command prompt.
- If you cannot access an event log, check to see if you are running from an Elevated command prompt. Some Event Log, such as the Security Event Log, may be protected by User Access Controls (UAC).
By default, cscript displays the output of a script in the command prompt window. Because WMI scripts can produce large amounts of output, you might want to redirect the output to a file. Type cscript filename.vbs > outfile.txt at the command prompt to redirect the output of the filename.vbs script to outfile.txt.
The following table lists script examples that can be used to obtain various types of data from the local computer.
|How do I...||WMI classes or methods|
|...create scheduled tasks using scripts?||Use the Win32_ScheduledJob class and the Create method. If you are having difficulty making this task work on Windows 7 or later, see the Win32_ScheduledJob Remarks section; likely your settings are preventing you from using the class.
In the string "********143000.000000-420" (used in the StartTime parameter value of the Create method), "********143000.000000" specifies that the task starts at 14.30 (2:30 P.M.) and "-420" specifies the time zone. The time zone number is the current bias of the 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.
|...return a list of all the scheduled tasks on a computer?||
Use the Win32_ScheduledJob class. Note that this class can only return jobs that are created using either a script or AT.exe. It cannot return information about jobs that are either created by or modified by the Scheduled Task wizard.