批量变量命令输入

时间:2015-07-24 10:01:39

标签: batch-file command netsh

我正在尝试创建一个为热点命名并输入密码的程序。我可以选择命名我的热点并输入密码。 如果您理解,请帮忙。

@echo off
Title KEVINS HOTSPOT UPLINK
mode 100, 25

//这是我的问题开始

echo Name your hotspot
set/p "ssid=>%name%"
echo Put a password for your hotspot:
set/p "key=>%key%"
netsh wlan set hostednetwork mode=allow ssid=%name% key=%key%
goto choice

//下面的代码

:choice
echo Hotspot Uplink
set/p "do=>"
if %do%==Start goto start
if %do%==start goto start
if %do%==Stop goto stop
if %do%==stop goto stop
if %do%==End goto end
if %do%==end goto end
goto choice

:start
cls
netsh wlan start hostednetwork
goto choice

:stop
cls
netsh wlan stop hostednetwork
goto choice

:end
cls
netsh wlan stop hostednetwork
echo Thank you for using Kevin's Hotspot Uplink!
pause

1 个答案:

答案 0 :(得分:1)

set /p "varName=prompt text to show to user"

所以,它应该像

set /p "ssid=Name your hotspot: "
set /p "key=Put a password for your hotspot: "
netsh wlan set hostednetwork mode=allow ssid=%ssid% key=%key%

当然你应该检查用户输入的内容(例如)

set "ssid="
set /p "ssid=Name your hotspot: "
if not defined ssid goto :eof

而且,如果用户输入空字符串,则if命令将失败。包括检查空值或引用要比较的字符串

:choice
    echo Hotspot Uplink
    set "do="
    set /p "do=>"
    if /i "%do%"=="start" goto start
    if /i "%do%"=="stop"  goto stop
    if /i "%do%"=="end"   goto end
    goto :choice