0% found this document useful (0 votes)
22 views3 pages

Batch Scripting Basics Tutorial

This document provides instructions and examples for creating batch script programs in Windows. It includes: 1. An example of a simple "Hello World" batch script and explanations of the @echo off and pause commands. 2. Instructions to create a script that takes two numeric inputs from the user and checks if they are equal. 3. Instructions to create a script that takes a single numeric input and checks if it is odd or even. 4. Instructions to create a script that prints the numbers 1 through 10 using a for loop. 5. Instructions to create a basic calculator script using batch that performs addition, subtraction, multiplication, or division based on a user's third input.

Uploaded by

Sanjaya Karki
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views3 pages

Batch Scripting Basics Tutorial

This document provides instructions and examples for creating batch script programs in Windows. It includes: 1. An example of a simple "Hello World" batch script and explanations of the @echo off and pause commands. 2. Instructions to create a script that takes two numeric inputs from the user and checks if they are equal. 3. Instructions to create a script that takes a single numeric input and checks if it is odd or even. 4. Instructions to create a script that prints the numbers 1 through 10 using a for loop. 5. Instructions to create a basic calculator script using batch that performs addition, subtraction, multiplication, or division based on a user's third input.

Uploaded by

Sanjaya Karki
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Fundamentals Of Computing Week 10 Tutorial

Instruction:
Complete all questions in 1 hr.
Let’s get started with nice and easy examples of Batch script:
1. Open your favorite text editor. Save it as [Link] (All files) right click on the file and
edit> type >
@echo off
echo Hello World!
pause
Run it. You have created your first batch file.
Write the function of set up commands @Echo off and pause.

2. Create a batch program which takes two numeric inputs from the user and checks
whether they are equal or not.

3. Create a batch program which takes a numeric input from the user and checks whether
the input is odd or even.
Fundamentals Of Computing Week 10 Tutorial

Output

4. Create a batch program which prints natural numbers 1 to 10 using for loop.

Output

5. Create a simple calculator using a batch script. Which takes two number and third inputs
can be “add” ,“sub”, “mul”, “div” and displays the result after calculation and displays
error message for any other input in the third. eg: if first input is 2 , second input is 3 and
third input is add then it displays the result 5. Note: use function
6. Write a batch program to swap mouse keys.
7. The following script is the malicious script responsible for system crash. Explain how it
works and explain how you can protect your pc from system crash in Windows OS and
Linux.
It is not permanently harmful for computers but annoying.
Warning: do not run this script.
:S
Start %0
Fundamentals Of Computing Week 10 Tutorial

Goto S

Common questions

Powered by AI

A Batch script uses the modulus operation to determine if a number is odd or even. It divides the number by 2 and checks the remainder. If the remainder is zero, the number is even; otherwise, it is odd. This logic involves user input handling and the modulo arithmetic operator, executed within an 'IF' conditional structure .

To swap mouse keys using a Batch script, the script can modify the Windows registry or use the built-in Windows utility 'setx' to change system settings. Essential commands can include invoking system configurations or specific utilities that provide the required functionality to swap left and right mouse button functionalities .

The Batch script uses a 'FOR' loop to iterate from 1 to 10. The loop structure initializes a variable, typically 'i', to 1 and increments it by 1 on each iteration, executing the specified command (echoing the variable). After reaching 10, the loop terminates. This involves loop initialization, condition check, and update mechanics in the 'FOR' loop syntax .

A Batch script calculator involves retrieving three inputs: two numbers and an operation ('add', 'sub', 'mul', 'div'). It uses an 'IF' statement to determine the operation, performing arithmetic based on the third input. The result is calculated and displayed using mathematical expressions and error-handling is done for unrecognized operations by showing an error message .

Developing Batch scripts involves ensuring compatibility with different Windows versions since command support can vary. Efficient script development requires understanding command syntax, handling errors gracefully, and using comments for clarity. Text editing tools with syntax highlighting can aid development, and extensive testing across Windows versions ensures functionality and efficiency .

To handle input errors in Batch scripts, structures like 'IF' statements and error-checking routines can verify user input, alert users to invalid data before proceeding. Providing feedback for correct input formats enhances usability. Use of 'GOTO' for directing flow to error-handling subroutines can manage exceptions and return meaningful error messages .

A Batch script can use conditional statements to check if two numbers are equal. By using the 'IF' command, the script compares the two inputs and if they match, displays a message indicating they are equal; otherwise, it shows they are not . Logical components crucial for this comparison include user input commands and the 'IF' statement to evaluate equality .

Running a Batch script with recursive execution commands can lead to infinite loops, causing high CPU usage and potential system crashes due to resource exhaustion. Users can safeguard their systems by not executing untrustworthy scripts, employing reliable antivirus software, and maintaining updated system backups to recover in case of a crash .

The '@echo off' command disables the display of the executed commands in the command prompt, effectively making the script output cleaner by only showing the results of the echo commands and not the commands themselves . The 'pause' command halts the execution of the batch script until the user presses any key, allowing the user an opportunity to view the output before the window closes .

The malicious script creates an infinite loop by calling itself recursively with the ':S Start %0' and 'Goto S' commands, consuming system resources, leading to a potential crash. To prevent such a crash, users should avoid running unknown or suspicious scripts and use antivirus software to detect harmful activities. Additionally, activating user account control (UAC) can help restrict unauthorized changes to the system .

You might also like