Windows 10 Cmd Read Text File Line by Line

On Windows x, a batch file typically has a ".bat" extension, and it is a special text file that includes one or multiple commands that run in sequence to perform various actions with Command Prompt.

Although yous can type commands manually to execute a item task or change system settings on Windows 10, a batch file simplifies the work of having to re-type the commands, saving y'all time and avoiding mistakes.

You tin can also apply other tools like PowerShell to write fifty-fifty more than advanced scripts. Nonetheless, running batch files in Control Prompt is all the same relevant to execute commands to alter settings, automate routines, and launch apps or spider web pages on your device.

In this Windows 10 guide, we will walk you through the steps to create and run a batch file. Also, we volition outline the steps to create advanced scripts and rum them automatically on schedule using the Job Scheduler.

  • How to create a batch file on Windows ten
  • How to run a batch file on Windows 10

How to create a batch file on Windows 10

The procedure of writing a batch file is straightforward. You simply demand Notepad or another text editor and some basic knowledge typing commands in Command Prompt. These instructions will help yous create a bones and advanced batch file to query system settings.

Create basic Windows 10 batch file

To create a basic batch file on Windows 10, use these steps:

  1. Open Starting time.
  2. Search for Notepad and click the elevation result to open up the text editor.
  3. Blazon the following lines in the text file to create a batch file:

                  @Repeat OFF Echo Hullo Globe! Your offset batch file was printed on the screen successfully. Pause                          

    Windows 10 basic batch file Source: Windows Central

    The higher up script outputs the phrase, "Hi World! Your first batch file was printed on the screen successfully," on the screen.

    Basic batch file output Command Prompt Source: Windows Central

    • @Repeat OFF — Shows the message on a clean line disabling the display prompt. Usually, this line goes at the beginning of the file. (You lot tin apply the command without the "@" symbol, but it's recommended to include it to show a cleaner return.)
    • Echo — The command prints the text after the space on the screen.
    • Break — Allows the window to stay open afterwards the control has been executed. Otherwise, the window will close automatically as shortly every bit the script finishes executing. You tin can utilise this control at the end of the script or after a specific command when running multiple tasks and desire to interruption between each line.
  4. Click the File menu.
  5. Select the Save equally option.
  6. Ostend a name for the script — for example, first_basic_batch.bat.

    Quick annotation: While batch files typically use the .bat file extensions, you tin can also find them using the .cmd or .btm file extensions.

Once you complete the steps, double-click the file to run it. Alternatively, you tin can utilise the steps below to acquire the different ways yous can run a batch file with Command Prompt, File Explorer, or Task Scheduler.

Create advanced Windows x batch file

To create an advanced Windows batch file with multiple commands, use these steps:

  1. Open Start.
  2. Search for Notepad and click the top issue to open up the text editor.
  3. Type the following lines in the text file to create a more advanced Windows 10 batch file:

                  @ECHO OFF  :: This batch file details Windows 10, hardware, and networking configuration. Championship My System Info ECHO Please expect... Checking system information. :: Section 1: Windows 10 information ECHO ========================== ECHO WINDOWS INFO Echo ============================ systeminfo | findstr /c:"OS Proper name" systeminfo | findstr /c:"Bone Version" systeminfo | findstr /c:"Arrangement Blazon" :: Section 2: Hardware information. Repeat ============================ Echo HARDWARE INFO ECHO ============================ systeminfo | findstr /c:"Total Physical Memory" wmic cpu go name wmic diskdrive get name,model,size wmic path win32_videocontroller get name wmic path win32_VideoController become CurrentHorizontalResolution,CurrentVerticalResolution :: Section 3: Networking information. ECHO ============================ Echo NETWORK INFO ECHO ============================ ipconfig | findstr IPv4 ipconfig | findstr IPv6 Outset https://back up.microsoft.com/en-us/windows/windows-10-arrangement-requirements-6d4e9a79-66bf-7950-467c-795cf0386715 PAUSE                          

    Advanced batch file script Source: Windows Central

    The higher up script runs each line to query a series of organisation details, and the upshot will be divided into three categories, including "WINDOWS INFO," "HARDWARE INFO," and "NETWORK INFO." Besides, the "Showtime" command will open the spider web browser in the official support page outlining the Windows 10 arrangement requirements, which you tin check confronting your information.

    Advanced batch file output Source: Windows Central

    • @ECHO OFF — Shows the message on a clean line disabling the display prompt. Normally, this line goes at the showtime of the file.
    • Championship — Prints a custom name in the championship bar of the console window.
    • :: — Allows writing comments and documentation data. These details are ignored when the system runs the batch file.
    • ECHO — Prints the text after the infinite on the screen.
    • START — Opens an app or website with the default web browser.
    • PAUSE — Tells the console window to stay open later on running the command. If you do not use this option, the window will shut automatically as soon as the script finishes executing.
  4. Click the File bill of fare.
  5. Select the Salvage every bit option.
  6. Type a proper name for the script — for example, first_advanced_batch.bat.

After you complete the steps, double-click the .bat file to run it or utilize the steps below to execute the script with Command Prompt, File Explorer, or Task Scheduler.

Create actionable Windows 10 batch file

You tin can as well write batch scripts for any job that does not require user interaction. For instance, to map a network drive, install an application, change system settings, and more.

To create a not-interactive batch file on Windows x, use these steps:

  1. Open Start.
  2. Search for Notepad and click the summit result to open the text editor.
  3. Type the post-obit command to map a network drive in the text file:

                  net utilise z: \\PATH-NETWORK-SHARE\Folder-NAME /user:YOUR-USERNAME YOUR-Countersign                          

    Map network drive script Source: Windows Primal

    In the command, supersede the \PATH-NETWORK-SHARE\FOLDER-NAME for the folder network path to mountain on the device, and YOUR-USERNAME YOUR-Password with the username and countersign that authenticates access to the network share.

    This example maps a network folder every bit a drive inside File Explorer using the "Z" drive alphabetic character:

    net use z: \\10.one.4.174\ShareFiles

    Script to mount network folder Source: Windows Central

    Quick annotation: The screenshot includes the "break" command, only this is not required. It was added in this example to take a screenshot of the console. If y'all are accessing the files from some other reckoner that uses a specific username and password, practise non forget to use the /user: option with the correct credentials.

  4. Click the File menu.

  5. Select the Save equally option.
  6. Confirm a proper name for the script — for example, mountain-z-network-bulldoze.bat.

In one case y'all consummate the steps, the batch file will map the network folder without opening a Command Prompt window.

Nosotros only demonstrate a script with a single control, but you can include as many equally you like, as long as y'all write them i per line.

How to run a batch file on Windows x

Windows 10 has at least three means to write batch files. You can run them on-demand using Command Prompt or File Explorer. Using the Task Scheduler app, you can configure the script to run it on schedule. Or you can save the batch files in the "Startup" binder to allow the system run them equally soon as you sign into the account.

Run batch file on-demand

If you want to run a script on-need, you tin can use File Explorer or Command Prompt.

Command Prompt

To run a script file with Command Prompt on Windows 10, utilize these steps:

  1. Open Start.
  2. Search for Command Prompt, right-click the height event, and select the Run as administrator option.
  3. Blazon the following command to run a Windows 10 batch file and press Enter:

    C:\PATH\TO\Binder\BATCH-Proper noun.bat

    In the control, make sure to specify the path and name of the script.

    This example runs the batch file located in the "scripts" binder within the "Downloads" binder:

    C:\Users\UserAccount\Downloads\first_basic_batch.bat

    Run batch file from Command Prompt Source: Windows Central

Afterwards you complete the steps, the console volition return the results, and the window won't close fifty-fifty if the script does non include the "PAUSE" command since you lot are invoking the script from within a console session that was already open.

File Explorer

To run a batch file with File Explorer, apply these steps:

  1. Open File Explorer.
  2. Browse to the folder with the batch file.
  3. Double-click the script file to run information technology.
  4. (Optional) If a control in the batch file requires administrator privileges, you volition have to run the script as an admin by right-clicking the file and selecting the Run equally administrator option.

    File Explorer run batch file as administrator Source: Windows Cardinal

  5. Click the Yes button

Once you complete the steps, the script will run each command in sequence, displaying the results in the panel window.

Run batch files on startup

Windows 10 too features a known folder chosen "Startup," which the organisation checks every time it starts to run applications, shortcuts, and scripts automatically without the need for extra configuration.

To run a script on the Windows 10 startup, use these steps:

  1. Open File Explorer.
  2. Open to the folder containing the batch file.
  3. Right-click the batch file and select the Copy option.
  4. Use the Windows primal + R keyboard shortcut to open the Run command.
  5. Type the following command:

    trounce:startup

    Run shell startup command Source: Windows Fundamental

  6. Click the OK button.
  7. Click the Paste pick from the "Home" tab in the Startup binder. (Or click the Paste shortcut button to create a shortcut to the batch file.)

    Configure script on startup folder Source: Windows Central

Afterwards you complete the steps, the batch file will execute automatically every fourth dimension you log into your account.

Run batch file with Task Scheduler

To utilize Task Scheduler to run the batch file automatically at a specific time, use these steps:

  1. Open First.
  2. Search for Chore Scheduler and click the superlative consequence to open up the app.
  3. Right-click the "Chore Scheduler Library" co-operative and select the New Folder option.
  4. Confirm a name for the folder — for example, MyScripts.

    Quick note: Yous don't need to create a folder, just keeping the organization and your tasks split is recommended.

  5. Click the OK button.
  6. Expand the "Task Scheduler Library" branch.
  7. Right-click the MyScripts folder.
  8. Select the Create Basic Task option.

    Task Scheduler create basic task Source: Windows Central

  9. In the "Proper noun" field, confirm a proper name for the task — for example, SystemInfoBatch.
  10. (Optional) In the "Description" field, write a description for the job.
  11. Click the Side by side button.
  12. Select the Monthly choice.

    Task trigger settings Source: Windows Cardinal

    Quick notation: Task Scheduler lets you choose from different triggers, including a specific date, during startup, or when a user logs in to the estimator. In this instance, we will select the option to run a task every month, but y'all may need to configure boosted parameters depending on your pick.

  13. Click the Next push.
  14. Use the "Start" settings to confirm the day and time to run the task.
  15. Utilise the "Monthly" driblet-downwards carte to selection the months of the year to run the task.

    Task Scheduler date selection Source: Windows Cardinal

  16. Utilise the "Days" or "On" drop-down menu to confirm the days to run the task.

    Schedule batch file day of the month Source: Windows Cardinal

  17. Click the Side by side button.
  18. Select the Start a program choice to run the batch file.

    Start a program action Source: Windows Central

  19. In the "Program/script" field, click the Browse button.
  20. Select the batch file you want to execute.

    Task Scheduler batch file location Source: Windows Key

  21. Click the Finish push button.

In one case you complete the steps, the task will run the script during the configured time and date or action.

The above instructions are meant to schedule only a basic task. You tin can apply these instructions to create a more customizable task with the Task Scheduler.

This guide focuses on Windows 10, only the same steps will besides work for older versions, including Windows 8.1 and Windows 7. Also, y'all tin refer to these instructions if you lot have Windows 11 installed on your computer.

More Windows resources

For more helpful manufactures, coverage, and answers to common questions about Windows 10 and Windows xi, visit the following resources:

  • Windows 11 on Windows Central — All y'all need to know
  • Windows 11 help, tips, and tricks
  • Windows ten on Windows Central — All y'all demand to know

brophygovey1976.blogspot.com

Source: https://www.windowscentral.com/how-create-and-run-batch-file-windows-10

0 Response to "Windows 10 Cmd Read Text File Line by Line"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel