Scheduling a Batch File
Once a batch file is created, it can be scheduled to run at any time. How the batch file (ListPatches.bat) created in the previous exercise can be scheduled. This exercise assumes the \\srv1\Patches share exists as mentioned in the previous exercise.
Scheduling a Batch File
- Launch Windows Explorer, and create a folder named Scripts in the C: drive.
- Copy the ListPatches.bat file created in the previous exercise to the C:\Scripts folder.
- Launch the Task Scheduler by clicking Start, typing Task in the search box, and selecting Task Scheduler from the search results. You can also access the Task Scheduler from the Administrative Tools menu.
- When Task Scheduler launches, select Create Basic Task from the Action pane on the right of the window.
- Name the task Document Patches and put in a description if desired. Click Next.
- On the Trigger page, select Weekly and click Next.
- Select Thursday and set the time to 3:00 PM to cause the script to run every Thursday afternoon at 3:00. Click Next.
- On the Action page, select Start A Program and click Next.
- Browse to C:\Scripts and select the ListPatches.bat file you copied to this location earlier. Click Next.
- Select the check box "Open the Properties dialog for this task when click Finish" and then click Finish.
- The Properties page will appear with the General tab selected. Click the Change User Or Group button.
- Enter System as the user and click OK. This will cause the script to run using the System account instead of your account. Your display will look similar to the following graphic. Click OK.
- Test your task using the following steps:
- Select Task Scheduler Library within the Task Scheduler, and locate your task.
- Right-click your task and select Run. Notice that you won't get any feedback indicating success or failure of the task.
- Select the History tab of the task in the middle pane. It should show that the task completed with a time stamp.
- Browse to the Patches share. Verify that the file has been copied to this share.
Note that you can use this script on as many computers as you like within your network to document the patches that are currently installed. If you need to verify that a certain patch has been installed on a certain computer, it's as simple as accessing the share and opening the text file to get your answer.
Of course, that's a lot of steps to create the task on all of your computers. If only there was a way to automate this process. How about a script? See Next Section....
In this tutorial:
- Working with the Command Prompt
- Starting and Ending a Command Prompt Session
- Easy ways to invoke administrator Command Prompt sessions
- Starting Command Prompt at a Particular Folder
- Strings with Spaces Need Quotes
- Cmd.exe vs. Command.com
- Commands Are Not Case Sensitive
- Starting Command Prompt and Running a Command
- Cmd.exe and Other Command Prompts
- Using AutoRun to Execute Commands When Command Prompt Starts
- Using Cmds Command-Line Syntax
- Using Commands
- Type /? for help
- Starting Programs
- Open Windows Explorer at the current Command Prompt folder
- Using File-Name and Folder-Name Completion
- Use a different completion character
- Using Wildcards
- Editing the Command Line
- Using Command Symbols
- The Redirection Symbols
- The Pipe Symbol
- The Command Combination Symbols
- Pausing or Canceling Commands
- Simplifying Command Entry with Doskey Macros
- DOSKEY Saves Typing
- System Variables Identify the Environment
- Viewing Environment Variables
- Modifying Environment Variables
- Predefined Environment Variables
- Customizing Command Prompt Windows
- Setting the Window Size and Position
- Setting the Window Size and Position Visually
- Selecting a Font
- Setting Colors
- Setting Other Options
- Copy and paste in the command prompt window
- Navigating from the command prompt
- Printing a list of filenames
- Commands Use Paths
- Identifying Executables
- Modifying the Path to Executables
- Modifying the Path with the GUI
- Changing the Current Path with CD
- Changing the Current Path with Windows Explorer
- Capturing the Output
- A Sampling of Commands
- Dir
- Copy
- XCopy
- SET
- NET USE
- SystemInfo
- DriverQuery
- Echo
- Advanced Shell Commands
- Creating a Batch File
- Scheduling a Batch File
- Creating Scheduled Tasks with a Script
- Using Windows PowerShell and the PowerShell ISE
- Windows PowerShell ISE
- PowerShell Commands
- Verbs and Nouns
- Sending Output to a Text File
- PowerShell Syntax
- Variables Created with a $ Symbol
- Comparison Operators
- Parentheses, Brackets, and Braces
- Running PowerShell Scripts
- PowerShell Execution Policy
- Changing the Execution Policy
- Looping
- Collections
- Creating a PowerShell Script
- Documenting Scripts
- Using PowerShell Commands
- Getting Help on PowerShell
- Using WMI_Cmdlets
- Getting Details on an Object
- Querying Information on Specific Objects
- Terminate Applications with Win32_process
- Formatting Output with the -f Format Operator
- Filtering the Output with the Where-Object Command
- Using the IF statement
- Using the Switch Statement
- Script Reusability