Windows 10

Batch File To Get Input From User

In this tutorial, we are going to see how to get input from user by using Set command. The batch file contains a series of DOS (Disk Operating System) instructions. It allows triggering the execution of commands found in this file.
 

Command To Get Input From User:
set /p Input=Enter Yes or No:

 

 

Batch File To Get Input From User

The following example ask the user if he want to shutdown the computer:

@echo off

echo DO YOU WANT YOUR COMPUTER TO SHUTDOWN? (y/n)
set /p Input=Enter Yes or No:
if /I "%Input%"=="y" goto yes
goto no

:yes
shutdown /s
:no
pause

Output:

DO YOU WANT YOUR COMPUTER TO SHUTDOWN? (y/n)
Enter Yes or No: No
Press any key to continue . . .

Leave a Reply

Your email address will not be published. Required fields are marked *