-->

ABOUT US

Our development agency is committed to providing you the best service.

OUR TEAM

The awesome people behind our brand ... and their life motto.

  • Kumar Atul Jaiswal

    Ethical Hacker

    Hacking is a Speed of Innovation And Technology with Romance.

  • Kumar Atul Jaiswal

    CEO Of Hacking Truth

    Loopholes are every major Security,Just need to Understand it well.

  • Kumar Atul Jaiswal

    Web Developer

    Techonology is the best way to Change Everything, like Mindset Goal.

OUR SKILLS

We pride ourselves with strong, flexible and top notch skills.

Marketing

Development 90%
Design 80%
Marketing 70%

Websites

Development 90%
Design 80%
Marketing 70%

PR

Development 90%
Design 80%
Marketing 70%

ACHIEVEMENTS

We help our clients integrate, analyze, and use their data to improve their business.

150

GREAT PROJECTS

300

HAPPY CLIENTS

650

COFFEES DRUNK

1568

FACEBOOK LIKES

STRATEGY & CREATIVITY

Phasellus iaculis dolor nec urna nullam. Vivamus mattis blandit porttitor nullam.

PORTFOLIO

We pride ourselves on bringing a fresh perspective and effective marketing to each project.

Showing posts with label IT support. Show all posts
Showing posts with label IT support. Show all posts
  • Batch Scripting Basics for Beginners: Variables, Comments, User Input, and Arithmetic Operations

     

    Batch Scripting Basics for Beginners: Variables, Comments, User Input, and Arithmetic Operations

     

     

    Batch Scripting Basics for Beginners: Variables, Comments, User Input, and Arithmetic Operations


    Batch scripting is one of the easiest ways to automate tasks in Windows. A batch file contains a series of commands that are executed by the Windows Command Prompt (CMD). System Administrators, IT Support Engineers, and System Engineers often use batch files for automation, troubleshooting, software deployment, and maintenance tasks.

    In this article, we will explore some fundamental concepts of batch scripting, including displaying output, using comments, working with variables, accessing environment variables, and performing arithmetic operations.




    Displaying Output with ECHO


    The echo command is used to display messages on the screen.


    echo off
    echo "Hello World from a batch file!"
    echo 1234
    echo Hello Atul
      


    Output

    "Hello World from a batch file!"
    1234
    Hello Atul



    Explanation

    • echo off hides the execution of commands.
    • echo displays text on the console.
    • It is commonly used to provide status messages to users.


    Understanding @ Symbol


    The @ symbol prevents the current command from being displayed before execution.


    //echo off
    @echo "This is for symbol.bat file"
    @vol
    @ver
    



    Explanation

    • @echo displays text without showing the command itself.
    • vol displays volume information of the current drive.
    • ver displays the Windows version.



    Sample Output

    "This is for symbol.bat file"
    Volume in drive C is Windows
    Volume Serial Number is XXXX-XXXX

    Microsoft Windows [Version 10.0.19045.XXXX]



    Working with Variables


    Variables are used to store values that can be reused throughout the script.


    @echo off
    rem set filename=echo.bat
    rem echo The name of the batch file is: %filename%
    set filename=dir
    echo The name of the batch file is: 
    %filename%
    
    


    Explanation

    • set creates a variable.
    • %filename% retrieves the stored value.
    • In this example, the variable contains the value dir.



    Output

    The name of the batch file is:

    Directory of C:\Users\Username

    Because %filename% contains the command dir, CMD executes it.



    Comments in Batch Files


    Comments help document scripts and improve readability.

    @echo off

    :: This is a comment in a batch file. It will not be executed.

    rem This is another way to write a comment in a batch file.
    echo This line will be executed, but the comments above will be ignored.




    Explanation

    There are two ways to write comments:

    REM
    ::

    Comments are ignored during execution and are useful for documenting code.

    Environment Variables

    Windows provides several built-in environment variables that contain system information.


    @echo off
    rem set
    ::cd %SystemRoot%
    ::dir
    
    echo Below is the cmd path
    echo %cmdcmdline%
    ::%ComSpec%
    echo %ComSpec%
    



    Explanation

    • %cmdcmdline%
    • Displays the command line that started the current CMD session.
    • %ComSpec%
    • Displays the path of the Command Prompt executable.



    Example Output

    Below is the cmd path
    C:\Windows\System32\cmd.exe

    C:\Windows\System32\cmd.exe

    These variables are useful when troubleshooting Windows systems.





    Arithmetic Operations


    Batch scripting supports basic mathematical calculations using set /a.


    @echo off
    
    set /a sum = 10+10
    echo The sum of 10 and 10 is: %sum%
    Output
    The sum of 10 and 10 is: 20
    More Arithmetic Examples
    
    Addition
    
    set /a result=15+5
    echo %result%
    
    Subtraction
    
    set /a result=20-5
    echo %result%
    
    Multiplication
    
    set /a result=5*5
    echo %result%
    
    Division
    
    set /a result=100/10
    echo %result%
    
    Modulus (Remainder)
    
    set /a result=10%%3
    echo %result%
    
    




    These operations are frequently used in automation scripts.




    Taking User Input


    Batch files can interact with users using set /p.


    @echo off
    
    rem echo Enter your name
    rem set /P name=
    
    rem echo Hello %name%, welcome to batch scripting!
    
    echo Enter the first number:
    set /P numb1=
    
    echo Enter the second number:
    set /P numb2=
    
    set /A sum = %numb1%+%numb2%
    
    echo %sum%
    
    



    Sample Execution

    Enter the first number:
    10

    Enter the second number:
    20

    30



    Explanation

    • set /p accepts input from the keyboard.
    • Values entered by the user are stored in variables.
    • set /a performs arithmetic calculations using those variables.


    This technique is commonly used in interactive administration scripts.

     

    Real-World Usage for System Engineers


    Batch scripting is useful for:

    • Automating repetitive tasks
    • Running maintenance scripts
    • Gathering system information
    • Managing files and folders
    • Creating startup and login scripts
    • Troubleshooting Windows systems
    • Automating software installation


    Even though modern organizations prefer PowerShell for advanced automation, understanding Batch scripting remains valuable because many legacy systems still use .bat files.


    Conclusion


    Batch scripting provides a simple way to automate Windows tasks. By learning commands such as echo, set, rem, environment variables, arithmetic operations, and user input handling, you build a strong foundation for Windows administration and automation.

     

     

     

  • WHAT WE DO

    We've been developing corporate tailored services for clients for 30 years.

    CONTACT US

    For enquiries you can contact us in several different ways. Contact details are below.

    Hacking Truth.in

    • Street :Road Street 00
    • Person :Person
    • Phone :+045 123 755 755
    • Country :POLAND
    • Email :contact@heaven.com

    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation.