Batch file

From XennisWiki
Jump to: navigation, search

A batch file is a kind of script file in DOS, OS/2 and Windows. It consists of a series of commands to be executed by the command line interpreter, stored in a plain text file. A batch file may contain any command the interpreter accepts interactively and use constructs that enable conditional branching and looping within the batch file, such as "if", "for", "goto" and labels. (Wikipedia)

Example

@echo off
::color F0
title WiFi Hotspot
 
:: Show menu
:menu
	echo Welcome, %USERNAME%
	echo What would you like to do?
	echo.
	echo "1. Config hotspot"
	echo "2. Start hotspot"
	echo "3. Stop hostspot"
	echo. 
	echo "0. Quit"
	echo.
	 
	set /p choice="Enter your choice: "
	if "%choice%"=="1" goto hotspot_config
	if "%choice%"=="2" goto hotspot_start
	if "%choice%"=="3" goto hotspot_stop
	if "%choice%"=="0" exit
	echo Invalid choice: %choice%
	echo.
	pause
	:: Clear window
	cls
	goto menu
 
:: Configurate hotspot
:hotspot_config
	set /p ssid="Enter WiFi name: "
	set /p key="Enter password (8 to 63 characters): "
	netsh wlan set hostednetwork mode=allow
	netsh wlan set hostednetwork ssid=%ssid% key=%key% keyUsage=temporary
	echo.
	echo Hotspot configured
	echo.
	goto menu

:: Start hostednetwork
:hotspot_start
	netsh wlan start hostednetwork
	echo.
	echo Hotspot started
	echo.
	goto menu
 
:: Stop hostednetwork
:hotspot_stop
	netsh wlan stop hostednetwork
	echo.
	echo Hotspot stopped
	echo.
	goto menu

External links