-->

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.

  • User Input Yes No Prompt in Batch Scripting

      

    User Input Yes No Prompt in Batch Scripting

     

    User Input Yes/No Prompt in Batch Scripting


    Many Batch Scripts require user confirmation before performing an action. For example, a script may ask whether you want to continue, delete a file, or restart a system.

    In such cases, we can use a **Yes/No Prompt** to collect user input and execute different actions based on the response.
    In this tutorial, we'll learn how to create a simple Yes/No prompt in Batch Scripting.



    Example Script

      
      
    @echo off
    
    :start
    cls
    set /p user_input=Do you want to continue? (yes/no)?:
    if not defined user_input goto start
    ::echo %user_input%
    if /i %user_input%==y goto Yes
    if /i %user_input%==n (goto No) else (goto InvalidInput)
    
    :: /i for upercase, lowercase, or mixed case letters. It makes the comparison case-insensitive.
    
    :Yes
    echo user has entered yes
    pause
    goto start
    
    :No
    echo user has entered no
    pause
    goto start
    
    :invalidInput
    echo %user_input% is an Invalid input. Please enter 'y' or 'n'.` 
    set user_input=
    pause
    goto start
      



    How the Script Works


    #Step 1: Ask for User Input

    set /p user_input=Do you want to continue? (yes/no)?:


    The user's response is stored in the variable:
    user_input


    Example:

    y
    OR
    n




    #Step 2: Check for Empty Input

    if not defined user_input goto start

    If the user presses Enter without typing anything, the script returns to the beginning and asks again.



    #Step 3: Handle "Yes"

    if /i %user_input%==y goto Yes

    If the user enters:
    y


    The script jumps to:
    :Yes



    Output:

    user has entered yes




    #Step 4: Handle "No"

    if /i %user_input%==n (goto No)
    If the user enters:
    n


    The script jumps to:
    :No


    Output:
    user has entered no



    #Step 5: Handle Invalid Input

    If the user enters something else:

    abc


    The script jumps to:
    :InvalidInput


    Output:


    abc is an Invalid input. Please enter 'y' or 'n'.
    The variable is cleared and the user is asked again.




    What Does /I Mean?




    The `/i` option makes comparisons case-insensitive.



    Example:



    The following inputs will all be treated as valid:
    y
    Y

    Without `/i`, Batch would treat uppercase and lowercase letters differently.



    Sample Output



    #User Enters Yes

    Do you want to continue? (yes/no)? y
    user has entered yes


    #User Enters No

    Do you want to continue? (yes/no)? n
    user has entered no


    #User Enters Invalid Value
    Do you want to continue? (yes/no)? hello

    hello is an Invalid input. Please enter 'y' or 'n'.





    Real-World Uses



    System Engineers often use Yes/No prompts for:

    • * Confirming software installations
    • * Starting backups
    • * Restarting services
    • * Deleting files or folders
    • * Running maintenance tasks
    • * Executing administrative scripts


    This helps prevent accidental actions.




    Interview Questions


    #What does `set /p` do?
    It takes input from the user and stores it in a variable.


    #What does `if not defined` do?
    It checks whether a variable is empty.


    #What does `/i` mean in an IF statement?
    It makes the comparison case-insensitive.


    #Why is input validation important?
    It prevents users from entering invalid values and improves script reliability.


    #What is the purpose of `goto`?
    It transfers execution to a specified label.



    Conclusion


    A Yes/No prompt is a simple but useful feature in Batch Scripting. It allows scripts to interact with users, validate input, and perform different actions based on the response. By combining `set /p`, `if`, and `goto`, you can build more interactive and user-friendly automation scripts.



  • ERRORLEVEL in Batch Scripting with Example

     

    ERRORLEVEL in Batch Scripting with Example

     

     

     ERRORLEVEL in Batch Scripting with Example


    When running commands in Batch Scripting, it is important to know whether a command was executed successfully or failed.



    This is where the **ERRORLEVEL** variable becomes useful.

    `ERRORLEVEL` helps us check the result of the previously executed command and take action based on success or failure.



    In this tutorial, we will learn how to use ERRORLEVEL with a practical example.

     What is ERRORLEVEL?


    `ERRORLEVEL` is a special system variable in Batch Scripting.


    After a command executes:

    * `0` usually means **Success**
    * Any non-zero value usually means **Error or Failure**



    Example


    text
    ERRORLEVEL = 0


    Means the command completed successfully.

    • ERRORLEVEL = 1



    Means an error occurred.



    Example: Checking a Folder Path


      @echo off
    
    set /P FolderPath=Enter the folder path:
    
     cd %FolderPath%
    
    if %ERRORLEVEL% EQU 0 (
          echo You entered the Correct path: %FolderPath% and it will exists
    ) else (
            echo You entered the Wrong path: %FolderPath%
    )
    
    
      

    How the Script Works


    Step 1

    The script asks the user to enter a folder path.

    set /P FolderPath=Enter the folder path:


    Example:

    C:\Users\user\Desktop


    Step 2

    The script attempts to change to the specified directory.


    cd %FolderPath%


    If the folder exists:

    ERRORLEVEL = 0



    If the folder does not exist:

    ERRORLEVEL = 1


    (or another non-zero value)


    Step 3

    The IF statement checks ERRORLEVEL.

    if %ERRORLEVEL% EQU 0

    If successful:

    • You entered the Correct path

    Otherwise:

    • You entered the Wrong path



    Example Output (Valid Path)

    • C:\Users\user\Desktop



    Output

    You entered the Correct path: C:\Users\user\Desktop and it will exists




    Example Output (Invalid Path)


    Input
    C:\InvalidFolder

    Output
    You entered the Wrong path: C:\InvalidFolder




    Why is ERRORLEVEL Important?



    ERRORLEVEL helps us:

    • * Detect command failures
    • * Validate user input
    • * Handle errors automatically
    • * Improve script reliability
    • * Create professional automation scripts


    Without ERRORLEVEL, a script may continue running even when something goes wrong.



    Real-World Uses for System Engineers


    System Engineers often use ERRORLEVEL for:

    • * Checking backup success
    • * Verifying software installation
    • * Network troubleshooting
    • * Validating file paths
    • * Monitoring scheduled tasks
    • * Automating maintenance scripts


    It is one of the most commonly used error-checking techniques in Batch Scripting.



    Interview Questions



    What is ERRORLEVEL in Batch Scripting?
    ERRORLEVEL is a system variable that stores the result of the last executed command.


    What does ERRORLEVEL 0 mean?
    It usually indicates that the command executed successfully.


    What does a non-zero ERRORLEVEL mean?
    It usually indicates an error or failure.


    Why is ERRORLEVEL used?
    It helps scripts detect and handle errors automatically.


    Can ERRORLEVEL be used with IF statements?
    Yes. It is commonly used with IF statements to check command results.



    Conclusion



    ERRORLEVEL is an essential feature in Batch Scripting that allows you to determine whether a command succeeded or failed. By combining ERRORLEVEL with IF ELSE statements, you can create smarter and more reliable scripts that handle errors effectively.

    As a future System Engineer or SecDevOps professional, understanding ERRORLEVEL will help you build automation scripts that are easier to troubleshoot and maintain.

  • FOR Loop in Batch Scripting with Examples

     

    FOR Loop in Batch Scripting with Examples


    FOR Loop in Batch Scripting with Examples


    When working with Batch Scripts, you may need to repeat the same task multiple times. Instead of writing the same command again and again, you can use a **FOR Loop**.

    The FOR Loop helps automate repetitive tasks such as displaying values, creating folders, processing files, and running commands multiple times.

    In this tutorial, we'll learn the basics of the FOR Loop using simple examples.



    What is a FOR Loop?


    A FOR Loop executes a block of code repeatedly for each item in a list.

    Syntax


    for %%variable in (list) do (
        command
    )


    Where:
     

    • `%%variable` stores the current value.
    • `list` contains the items to process.
    • `do` specifies the command to execute.



    Example 1: Display Numbers Using FOR Loop


    @echo off
    setlocal
    for %%i in (1 2 3 4 5) do (
        echo %%i
    )


    Output

    1
    2
    3
    4
    5



    Explanation


    In this example:

    • `%%i` acts as the loop variable.
    • The loop processes each value one by one.
    • The `echo` command displays the current value.



    Execution Flow:


    Iteration 1 → 1
    Iteration 2 → 2
    Iteration 3 → 3
    Iteration 4 → 4
    Iteration 5 → 5



    Example 2: Create Multiple Folders


    @echo off
    setlocal
    for %%i in (1 2 3 4 5) do (
        mkdir Folder-atul-%%i
    )

     

    Result


    The script creates the following folders:


    Folder-atul-1
    Folder-atul-2
    Folder-atul-3
    Folder-atul-4
    Folder-atul-5


     

    FOR Loop in Batch Scripting with Examples

     

     

     

    Explanation

    For each number:

    * The loop runs once.
    * `mkdir` creates a new folder.
    * `%%i` is appended to the folder name.

    This saves time compared to manually creating multiple folders.



    Why Use FOR Loops?


    FOR Loops are useful when:

    • * Creating multiple folders
    • * Renaming files
    • * Processing log files
    • * Running repetitive commands
    • * Automating administrative tasks




    Instead of writing:


    mkdir Folder1
    mkdir Folder2
    mkdir Folder3
    mkdir Folder4
    mkdir Folder5


    you can use a single FOR Loop.


    Real-World Uses for System Engineers

    System Engineers commonly use FOR Loops for:

    • Bulk folder creation
    • File management
    • Log collection
    • Backup automation
    • Software deployment tasks
    • User account processing



    FOR Loops are one of the most frequently used automation tools in Batch Scripting.





    Interview Questions


    What is a FOR Loop?
    A FOR Loop is used to repeat a command for each item in a list.


    What does %%i represent?
    It is the loop variable that stores the current value during each iteration.


    Why are FOR Loops useful?
    They reduce repetitive code and automate repetitive tasks.


    Which command is used to create folders?
    mkdir


    Can FOR Loops be used in automation scripts?
    Yes. They are widely used in system administration and automation tasks.



    Conclusion


    The FOR Loop is one of the most powerful features of Batch Scripting. It allows you to repeat tasks efficiently and automate routine operations. Whether you're displaying values, creating folders, or processing files, mastering FOR Loops will make your scripts cleaner and more effective.

    As a future System Engineer or SecDevOps professional, understanding loops is an important step toward automation and scripting mastery.
     

     

     

     

  • IF Statement and IF ELSE Statement in Batch Scripting

     

     

    IF Statement and IF ELSE Statement in Batch Scripting



    IF Statement and IF ELSE Statement in Batch Scripting



    When writing Batch Scripts, we often need to make decisions based on conditions. This is where the IF and IF ELSE statements are used.

    They allow a script to perform different actions depending on whether a condition is true or false.

    In this tutorial, we will learn how to use IF and IF ELSE statements with practical examples.

     

     

    What is an IF Statement?


    An IF statement executes a block of code only when a specific condition is true.

    Syntax

    if condition (
        command
    )



    Example 1: Basic IF Statement



      
    @echo off
    
    goto:main
    :main
    
    set /A number=5
    if %number% equ 5 (echo This is IF statement)
    
    goto:eof
    
      



    Output

    This is IF statement




    Explanation


    In this example:

    • A variable named number is created.
    • The value of number is set to 5.
    • The IF statement checks whether the value equals 5.
    • Since the condition is true, the message is displayed.



    The keyword:

    equ
    means equal to.


    Example 2: Checking a User Path



      
      @echo off
    
    goto:main
    
    :main
    
    set /P path= Enter path
    if %path% EQU C:\Users\user\Desktop\batch-scripting (
        cd %path%
        dir
    
    )
    
    goto:eof 
     
     
     
    IF Statement and IF ELSE Statement in Batch Scripting

     



    How It Works


    User enters a path.
    Batch compares the entered value with the specified path.

    If both match:

    • The script changes to that directory.
    • The contents of the folder are displayed using dir.



    Sample Input
    C:\Users\user\Desktop\batch-scripting


    Sample Output
    Directory of C:\Users\user\Desktop\batch-scripting


    This type of validation is commonly used in automation scripts.



    What is an IF ELSE Statement?


    The IF ELSE statement allows us to execute one block of code when a condition is true and another block when the condition is false.


    Syntax

    if condition (
        commands
    ) else (
        commands
    )



    Example: IF ELSE Statement


      
    @echo off
    goto:main
    :main
    set /P path= Enter path
    if %path% EQU C:\Users\user\Desktop\batch-scripting (
        cd %path%
        dir
    )
     else (
        echo Invalid path
    )
    goto:eof
    
      



    Explanation


    The script checks the path entered by the user.

    If the path is correct
    C:\Users\user\Desktop\batch-scripting


    The script:

    • Changes to the directory
    • Displays folder contents
    • If the path is incorrect
    • D:\Projects


    The script displays:

    Invalid path

    This makes scripts more user-friendly because they can handle both valid and invalid inputs.



    Common Comparison Operators


    IF Statement and IF ELSE Statement in Batch Scripting



    Example


    if %number% GTR 10 (
        echo Number is greater than 10
    )



    Real-World Uses of IF Statements


    System Engineers and IT Administrators commonly use IF statements for:

    • Checking whether a file exists
    • Validating folder paths
    • Verifying user input
    • Monitoring services
    • Automating troubleshooting tasks
    • Running backup scripts



    Interview Questions



    What is an IF statement in Batch Scripting?
    An IF statement executes commands only when a specified condition is true.


    What is the purpose of ELSE?
    ELSE executes an alternative block of code when the IF condition is false.


    What does EQU mean?
    EQU stands for "Equal To".


    Which command is used to take user input?
    set /P


    Why are IF statements important?
    They allow scripts to make decisions and automate tasks based on conditions.



    Conclusion


    The IF and IF ELSE statements are fundamental concepts in Batch Scripting. They help automate decision-making and make scripts more interactive. Whether you are validating user input, checking files, or automating system administration tasks, conditional statements are an essential skill for every Batch Scripting learner.




  • Local Scope vs Global Scope in Batch Scripting

     

    Local Scope vs Global Scope in Batch Scripting

     

     Understanding Local Scope and Global Scope in Batch Scripting



    Variables are one of the most important components of Batch Scripting. As scripts become larger, managing variables properly becomes essential. This is where the concepts of Local Scope and Global Scope come into play.

    In this article, we will understand how SETLOCAL and ENDLOCAL work and how they affect variable visibility inside a Batch Script.

    Learn Local Scope and Global Scope in Batch Scripting with practical examples. Understand SETLOCAL, ENDLOCAL, variable visibility, and best practices for Windows automation and System Administration.

    What is Variable Scope?


    Variable scope determines where a variable can be accessed within a script.

    In Batch Scripting there are two common scopes:

    • Global Scope
    • Local Scope


    Understanding the difference helps prevent unexpected behavior when writing automation scripts.

     

    Understanding SETLOCAL


    Example Script

      
      
    @echo off
    
    goto :displayname
    
    :displayname
    setlocal
    set /P name=Enter your name:
    echo Hello, %name%!
    endlocal
    
    goto: eof
      



    The command:

    setlocal

    creates a local environment.

    Any variable created after SETLOCAL exists only inside that local block.

    Example:

    setlocal
    set name=Atul

    The variable name is local.
    Once the script reaches:
    endlocal
    the variable disappears.




    Understanding ENDLOCAL

    @echo off
    
    goto :displayname
    
    :displayname
    setlocal
    set /P name=Enter your name:
    echo Hello, %name%!
    endlocal
    
    set /P number=Enter a number:
    echo You entered: %number%
    
    goto: eof
    
    


    The command:

    endlocal

    terminates the local environment and restores the previous environment.

    Example:

    • setlocal
    • set name=Atul
    • endlocal

    After ENDLOCAL, the variable:

    %name%

    is no longer available.





     


    Step-by-Step Execution of the Script



    Step 1

    Execution starts here:

    • goto :displayname
    • Control jumps to:
    • :displayname





    Step 2

    A local environment is created:

    • setlocal

    Now all variables created afterward are local.




    Step 3

    User enters a name:

    • set /P name=Enter your name:




    Example:
    Enter your name: Atul



    Variable value:
    name = Atul



    Step 4

    Display the value:
    echo Hello, %name%!


    Output:
    Hello, Atul!



    Step 5

    Local environment ends:
    endlocal

     

    Now the variable:
    name
    no longer exists.


    Step 6

    User enters another value:
    set /P number=Enter a number:


    Example:

    25

    Since this variable is declared outside the local block, it remains available.

    Output:
    You entered: 25


    What is Global Scope?


    A global variable is accessible throughout the entire script.


    Example:

      
    @echo off
    
    set company=HackingTruth
    
    echo %company%
    
    goto:eof
      


    Output:

    HackingTruth


    The variable remains available until:

    • Script ends
    • Variable is modified
    • Variable is deleted



    Example of Local Scope


      @echo off
    setlocal
    
    set username=Atul
    echo %username%
    
    endlocal
    echo %username%
      


    Output:
    Atul

    Second output:

    (blank)

    Because username exists only inside the local environment.



    Example of Global Scope

    @echo off
    
    set username=Atul
    
    echo %username%
    
    echo %username%
    



    Output:

    Atul
    Atul

    The variable is available everywhere in the script.


    Why Use Local Scope?


    Local variables are useful when:

    • Creating reusable functions
    • Preventing accidental variable modification
    • Testing code
    • Building large automation scripts


    Benefits:

    • Better script organization
    • Reduced bugs
    • Cleaner variable management

     

     

     

    Real-World Example


    Suppose a System Engineer writes a backup script.

    Without local scope:

    • set backup=C:\Backup
    • Another function may accidentally overwrite:
    • set backup=D:\Temp




    Result:

    • Backup process fails
    • Wrong directory used


    Using SETLOCAL prevents such conflicts.




    Preserving a Variable After ENDLOCAL


    Sometimes you want to keep a variable after ENDLOCAL.

    Example:

      @echo off
    setlocal
    set username=Atul
    endlocal & set username=%username%
    echo %username%
      



    Output:

    Atul

    This technique is commonly used in advanced Batch scripts.




    Local Scope vs Global Scope

     

    Local Scope vs Global Scope in Batch Scripting



    Real-World Uses for System Engineers



    Local Scope is useful for:

    • Software deployment scripts
    • Backup automation
    • User provisioning scripts
    • Active Directory automation
    • Network troubleshooting tools
    • System inventory collection




    Global Scope is useful for:

    • Configuration values
    • Common paths
    • Server names
    • Shared settings




    Interview Questions



    What is SETLOCAL in Batch Scripting?

    • SETLOCAL creates a local environment where variables exist only within that block.


    What is ENDLOCAL?

    • ENDLOCAL ends the local environment and removes local variables.


    What is the difference between Local Scope and Global Scope?

    • Local variables are available only inside a SETLOCAL block, while global variables remain available throughout the script.


    Why should System Engineers use SETLOCAL?

    • It prevents variables from interfering with other parts of the script and improves maintainability.


    What happens to variables after ENDLOCAL?

    • They are removed unless specifically preserved.



    Conclusion


    Understanding Local Scope and Global Scope is essential for writing professional Batch Scripts. Using SETLOCAL and ENDLOCAL allows you to create safer and more maintainable automation scripts. As your scripts grow in complexity, proper scope management becomes increasingly important.

    For aspiring System Engineers and future SecDevOps professionals, mastering variable scope is a foundational skill that helps build reliable Windows automation solutions.





  • Batch Scripting Functions Explained: CALL, GOTO, EXIT and EXIT /B with Examples

     

     

    Understanding Functions in Batch Scripting: CALL, GOTO, EXIT, and EXIT /B

     

     

    Understanding Functions in Batch Scripting: CALL, GOTO, EXIT, and EXIT /B


    As batch scripts become larger, writing all commands in a single block can make the script difficult to maintain. Functions help organize code into reusable sections, making scripts easier to read and manage.

    In this article, we will learn how functions work in Batch Scripting using labels, the CALL command, GOTO, EXIT, and EXIT /B.

    Learn Batch Scripting functions with practical examples. Understand CALL, GOTO, GOTO :EOF, EXIT, and EXIT /B to build reusable Windows automation scripts for System Administration and System Engineering.

     

    What is a Function in Batch Scripting?


    Unlike programming languages such as Python or Java, Batch scripting does not have traditional functions. Instead, functions are simulated using labels.

    A label begins with a colon (:).


    Example:

    :function1
    
    You can jump to a label using:
    
    goto:function1
    
    or call it using:
    
    call:function1
      

     

    Basic Function Example

      
      
    @echo off 
    :function1
    
    echo This is function 1
    
    :function2
    
    echo This is function 2
    
    call:function1
      

    Explanation


    In this script:

    Two labels are created.
    function1 prints a message.
    function2 prints another message.
    call:function1 invokes function1.



    Output

    This is function 1
    This is function 2
    This is function 1



    Important Note

    Without goto statements, Batch continues reading the script from top to bottom, executing labels as it encounters them. 

     

    Using GOTO to Control Execution



    The goto command transfers execution directly to a specific label.

    Example:

      
      @echo off
    
    goto:function3
    
    :function1
        echo This is function 1
    
    :function2
        echo This is function 2
        goto:eof
    
    :function3
        echo This is function 3
        call:function1
      




    How It Works


    Step 1

    Script starts at:

    • goto:function3
    • Execution jumps directly to:
    • :function3




    Step 2

    Output:

    • This is function 3



    Step 3

    • call:function1 executes:
    • This is function 1


    Output


    This is function 3
    This is function 1

    Notice that function2 is skipped because execution never reaches it.




    Understanding GOTO


    One of the most useful statements in Batch scripting is:

    • goto:eof


    EOF means End Of File.



    When a called function reaches:

    • goto:eof


    execution returns to the line immediately after the CALL statement.



    Example:



    • :function2
    • echo This is function 2
    • goto:eof


    This behaves similarly to a return statement in other programming languages.

    Function Example with EXIT



    Example:

      
      
    @echo off
    
    goto:function3
    
    :function1
        echo This is function 1
    
    :function2
        echo This is function 2
        timeout 5
    exit
    
    :function3
        echo This is function 3
        call:function1
    
      


    Explanation

    Here:

    • exit


    terminates the entire Command Prompt session.

    If this script reaches the exit command:

    • CMD window closes.
    • Remaining commands do not execute.



    Why Use EXIT?


    Useful for:

    Ending automation tasks
    Stopping deployment scripts
    Exiting maintenance operations

    However, it should be used carefully because it closes the current command interpreter.



    Understanding EXIT /B


    A safer alternative is:

    exit /B

    Example:

      
      @echo off
    
    goto:function3
    
    :function1
        echo This is function 1
    
    :function2
        echo This is function 2
        exit /B 0
    
    :function3
        echo This is function 3
        call:function1
    
    
      


    What Does EXIT /B Do?


    Instead of terminating CMD:

    • exit /B

    only exits the current function or batch script context.



    The command:

    • exit /B 0


    returns an exit code of 0.



    Meaning of Exit Codes


    Batch Scripting Functions Explained: CALL, GOTO, EXIT and EXIT /B with Examples

     

     

     CALL vs GOTO



    Many beginners confuse these commands.

    • CALL
    • call:function1
    • Executes the function
    • Returns to the next line after completion



    Example:


    • Start
    • Function1
    • Back to Start
    • GOTO
    • goto:function1
    • Jumps permanently
    • Does not return automatically




    Example:

    • Start
    • Function1


    Execution continues from the new location.




    Real-World Uses for Functions



    Functions are useful when:


    • Displaying menus
    • Automating backups
    • Creating reusable code blocks
    • Network troubleshooting scripts
    • Software deployment scripts
    • User management automation
    • System information collection



    Instead of writing the same commands repeatedly, create one function and call it whenever needed.



    Practical Example: System Information Function

     

    @echo off
    
    call:sysinfo
    goto:eof
    
    :sysinfo
    echo Hostname:
    hostname
    
    echo.
    echo Current User:
    whoami
    
    echo.
    echo IP Configuration:
    ipconfig
    
    goto:eof
    

     

     


    Benefits:


    • Cleaner code
    • Easier maintenance
    • Reusable logic


    Interview Questions


    What is a function in Batch Scripting?

    A function is a labeled section of code that can be executed using the CALL command.



    What is the difference between CALL and GOTO?

    CALL returns to the original location after execution, while GOTO permanently jumps to another label.



    What does GOTO do?

    It exits the current function and returns control to the calling statement.



    What is EXIT /B?

    It exits the current batch context without closing the entire Command Prompt window.



    Why are functions useful?

    Functions improve code reusability, readability, and maintainability.



    Conclusion



    Functions are one of the most important concepts in Batch scripting. By understanding labels, CALL, GOTO, GOTO :EOF, EXIT, and EXIT /B, you can write structured and reusable scripts rather than long, repetitive command files.

    For System Engineers and future SecDevOps professionals, mastering functions is essential because real-world automation scripts often depend on reusable code blocks and proper flow control.


  • 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.