0

My batch file code is like this:

@echo off

C:\Windows\System32\netsh.exe wlan set hostednetwor mode=allow ssid=User_Name key=password eyUsage=persistent

In this code the "User_name" and "password" fields I want the input from the user after running the batch file. How do I make it ??? Please help. And also suggest me modifications in this code if any.

John DOE
  • 400
  • 1
  • 3
  • 18
  • Try `set /p` for more information type `set /?` on command-line. – John DOE Nov 08 '14 at 13:31
  • Thank you sir for your help but Im not getting how to execute it in the code. Please tell me in detail. – SwaPnil Magar Nov 08 '14 at 13:38
  • possible duplicate of [In Windows cmd, how do I prompt for user input and use the result in another command?](http://stackoverflow.com/questions/1223721/in-windows-cmd-how-do-i-prompt-for-user-input-and-use-the-result-in-another-com) – Andriy M Nov 08 '14 at 13:45

1 Answers1

0
@ECHO OFF
:Values
SET strSSID=
SET strPWD=
ECHO Please enter the ssid:
SET /p strSSID=SSID: 
ECHO.
ECHO Please enter the password:
SET /p strPWD=Password: 

IF ".%strSSID%"=="." GOTO :TryAgain
IF ".%strPWD%"=="." GOTO :TryAgain

CALL :HostedNW "%strSSID%" "%strPWD%"
GOTO :EOF

:HostedNW
ECHO NETSH WLAN SET hostednetwork mode=allow ssid="%~1" key="%~2" keyUsage=persistent
SET strSSID=
SET strPWD=
GOTO :EOF

:TryAgain
  CLS
  ECHO.
  ECHO One or more inputs weren't correct.
  ECHO Please try again.
  ECHO.
  GOTO :Values

I'm not familiar with netsh wlan hostednetwork. If there are always entered stings without spaces, the code could be simpler.

BaBa
  • 337
  • 2
  • 10