How to get user input in a batch (Bat) script

Posted by Dark Training on August 10, 2007 tags: | windows | batch

Example shown: Getting a input variable from a user

Batch user input text example:

 
 @echo off
  Echo =============================================
  echo     User input example
  Echo =============================================
  set /p user_name=What is your user name:
  Echo %user_name% was what you typed
  pause

You may be saying, big deal, you can set a name. Well this can be a critical step in the creation of tools for any administrators automation kit.

Another example of this assumes that you are in an active directory enviroment. This tool will allow you to enter a users name and check that users account information without having to load the AD toolkit.

 
 @echo off
  Echo #####################
  Echo This tool will help you get the users info 
  Echo #####################
  set /p user=What is the User name to query:
  net user %user% /domain
  pause
  exit