Question

In: Computer Science

. Create a batch file (hw3_yourlastname1.bat) which will schedule tasks on the system using Windows 10’s...

. Create a batch file (hw3_yourlastname1.bat) which will schedule tasks on the system using Windows 10’s Scheduled Task Console utility - schtasks

Your batch file (hw3_yourlastname1.bat) will include instructions to do the followings:

a. List the directories and files in the current directory

b. Pause the script to see the list of directories and files

c. Clear the screen

d. Pause the script

e. Schedule a task to start Check Disk (chkdsk.exe) every Friday at 5:30pm using Scheduled Task Console (schtasks) utility

f. Schedule a task to start Disk Defragmenter (dfrgui.exe) every 1st day of a month at 11:30pm using Scheduled Task Console (schtasks) utility

g. Display all the scheduled tasks on the system

h. Pause the script to see the list of scheduled tasks

Solutions

Expert Solution

tep 1: Select and open your editor

As mentioned earlier, text documents are a good starting point for batch scripts. To write your own batch file, all you need is an ordinary text editor. You don’t really need features like syntax highlighting, so the Notepad application included with Windows is perfect. To open it, simply type “Notepad” in the Windows search bar and click on the Notepad icon in the search results:

ou don’t have to learn complicated programming language to create batch files. But you doneed to know common system commands and understand how they work in batch files. That’s why you should familiarize yourself with some commands before writing your first script. Here are the most important commands to learn:

  • ECHO: Turns on the on-screen text display for executed commands
  • @ECHO OFF: Turns off the on-screen text display for executed commands
  • START: Runs a file with its default associated application
  • REM: Indicates a comment line
  • MKDIR/RMDIR: Creates or deletes a directory
  • DEL: Deletes selected file(s)
  • COPY: Copies selected file(s)
  • TITLE: Sets the title of the CMD window
  • n easy introduction to the art of creating batch files is to write a simple script that creates multiple directories on a selected disk on your computer. For example, if you create and run a batch file with the following input, it will create two directories named “Example1” and “Example2” on drive C:

    MKDIR C:\Example1
    MKDIR C:\Example2

    Simply copy the two lines into an empty Notepad document, as shown in the following screenshot:

    To save these batch instructions or the script, click File and choose Save As... Specify the save location and enter a name for the script with the extension .bat in the File Name field:

    Step 4: Run the new batch script

    After you create and save the batch file, you have two options to run it: Either run the script in the familiar Windows Explorer environment or open Command Prompt and run it using a command-line command.

    The first option is simpler and easier for beginners because all you have to do is go to the directory where the batch file is located and double-click to run it.

  • If you want to open the batch file from the command line instead, do the following:

  • Go to the Windows search bar and type cmd.
  • Click Command Prompt to open the command line in the standard way. If you need administrator privileges to run it, right-click Command Prompt and then choose Run as Administrator.
  • Use the “Change directory” command (cd) to go to the directory where the batch file is located.
  • Type the name of the batch script (including the file extension) and press Enter.
  • Step 5: Editing batch files retrospectively

    You can customize a batch script at any time, for example if you want to add or remove commands or modify directories. To do this, simply go to the folder containing the command line script and right-click it. Then choose Edit:

    Examples of more frequently used and complex batch scripts

    With the above step-by-step guide, you can create a wide variety of batch files with an unlimited number of different commands. However, scripts that you can use more frequently are definitely more useful in the long run. We’ll conclude with two examples of batch files with long-term value to illustrate the possibilities of batch processing with Windows Command Prompt.

    Batch script with simple backup mechanism

    The following example shows how useful batch files can be for creating regular back-ups of any directory:

    XCOPY C:\Outgoing directory C:\Back-up-directory /m /e /y

    When you create and run a batch file containing the line shown above, use the “xCOPY” command to copy the contents from the “source folder” to the “back-up folder.” You’ll need to adjust the directories containing these two folders accordingly. The three parameters at the end have the following effect:

  • /m: Ensures that only updated files are copied so that files that have already been backed up don’t have to be copied again during further back-up operations.
  • /e: Indicates that the back-up includes all subdirectories in the specified directory.
  • /y: Suppresses prompting to confirm that you want to overwrite an existing destination file that was changed since the last backup.
  • Batch file with complex backup function

    The above backup program allows you to copy the source files from the source folder to the destination folder. You can also create a batch file that distributes source data to multiple destination folders, in which case you can use the file type as a selection criterion. To do this, you need a for loop, which allows a command to run repeatedly with a variable argument:

    cd C:\Outgoing directory
    FOR %%f IN (*.doc *.txt) DO XCOPY C:\Outgoing directory"%%f" C:\Back-up-directory\Texte /m /y
    FOR %%f IN (*.jpg *.png *.bmp) DO XCOPY C:\Outgoing directory "%%f" C:\Back-up-directory\images /m /y

    The batch code shown above ensures that:

  • all files in the source directory with the .doc and .txt extensions are moved to the “Text” back-up folder.
  • all files in the source directory with the .jpg, .png and .bmp extensions are moved to the “Images” backup folder.
  • only updated files are copied.
  • the confirmation prompt is always suppressed.

Related Solutions

Create a cronjob which does the following tasks 1.) create a file named <yourname>.txt 2.) in...
Create a cronjob which does the following tasks 1.) create a file named <yourname>.txt 2.) in the 35th minute of the hour change the permission to 755 3.) Create a shell script named first.sh in which you print your name and redirect the output by 45th minute of the hour to the text file
Using node.js, create the following tasks. 1. Set up a server and HTML file server as...
Using node.js, create the following tasks. 1. Set up a server and HTML file server as shown in the videos. Once you have it successfully running, make the following adjustments A. When a 404 error (file not found) occurs, display a funny message about the file missing and/or did you forget how to type? B. If the user enters a request for the home page (index.html) then: Display an index.html page you have created which includes your name, course number,...
Based on the information below, create a project schedule (Gantt Chart). Assign tasks to either Workgroup...
Based on the information below, create a project schedule (Gantt Chart). Assign tasks to either Workgroup or Individual. Project: Vacation Team: "Workgroup 1", "Individual" Start/End: February 19 - May 26 START A. February 19: Vacation participation must be confirmed Time allotted: 7 days i. Confirm participation Time needed: 1 day ii. Research vacation deals Time needed: 1 days iii. Decide on destination Time needed: 2 days iv. Create travel list Time needed: 1 day Slack available: 2 days B. February...
PYTHON. Tasks: Create and test the openFileReadRobust() function to open file (for reading) whose name is...
PYTHON. Tasks: Create and test the openFileReadRobust() function to open file (for reading) whose name is provided from the standard input (keyboard) – the name is requested until it is correct Create and test the openFileWriteRobust () function to open file (for writing) whose name is provided from the standard input (keyboard) – the name is requested until is correct Extend the program to count number of characters, words and lines in a file as discussed in the classby including...
Create a batch file that gathers network information from a remote host. Use your VMs for...
Create a batch file that gathers network information from a remote host. Use your VMs for this
USING YOUR KNOWLEDGE OF MODULES, REWRITE THE FOLLOWING BATCH OF CODE USING PSEUDOCODE AND CREATE A...
USING YOUR KNOWLEDGE OF MODULES, REWRITE THE FOLLOWING BATCH OF CODE USING PSEUDOCODE AND CREATE A FLOWCHART TO REPRESENT THE LOGIC: There’s one thing every coder must understand. The System.out.println command. There’s one thing every coder must understand. The System.out.println command.
create a todo app using React and MongoDB. User can also delete the tasks, add tasks,...
create a todo app using React and MongoDB. User can also delete the tasks, add tasks, update tasks and edit tasks using edit, del, update and add button.
Develop an iteration schedule diagram using the information provided in the attached document. Create this schedule...
Develop an iteration schedule diagram using the information provided in the attached document. Create this schedule using either Microsoft Project or ProjectLibre. Discipline Activity Effort Planning Set up work environment 2 days Develop WBS and plan work 1 day Analysis Activities Meet with Community Board users 2 days Meet with several agents 2 days Define data 1 day Model use cases 2 days Design Activities Design screen layouts 3 days Design Database 1 day Design use case processing 3 days...
Create a high-level design for a home alarm system. Assume that there are 4 windows and...
Create a high-level design for a home alarm system. Assume that there are 4 windows and 2 doors. The windows and doors have light sensors, so if any object crosses the light path, an appropriate event will be registered. Also, each window and door has latches with sensors that detect if the latch has been turned. Your solution will consist of the following parts 1.       Use a variable “Armed” to allow a user to arm the alarm system. So if a...
Write a program, which reads a list of student records from a file in batch mode....
Write a program, which reads a list of student records from a file in batch mode. Each student record comprises a roll number and student name, and the student records are separated by commas. An example data in the file is given below. · SP18-BCS-050 (Ali Hussan Butt), SP19-BCS-154 (Huma Khalid), FA19-BSE-111 (Muhammad Asim Ali), SP20-BSE-090 (Muhammad Wajid), SP17-BCS-014 (Adil Jameel) The program should store students roll numbers and names separately in 2 parallel arrays named names and rolls, i.e....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT