2016-08-23 7 views
1

私はバッチファイルのダブラーですので、私の知識は私の経験に限られています。私がしようとしているのは、 "YまたはN"入力をそのYまたはNだけに制限することです。今はフィールドに何かを置くことができ、コードが進行します。私がしようとしているのは、バッチファイルを使用してホットスポットを作成することです。私はまだ作成されたネットワークを "保存"する方法を見つけ出すことができませんでしたが、それは実際問題ではありません。バッチファイルのY文またはN文

私は自分の持っているものを含めていますが、行は開始と終了です。誰かが何か改善の余地があると感じたり、

@echo off 
:: BatchGotAdmin 
:------------------------------------- 
REM --> Check for permissions 
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" 
REM --> If error flag set, we do not have admin. 
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges... 
    goto UACPrompt 
) else (goto gotAdmin) 
:UACPrompt 
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" 
    echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs" 
    "%temp%\getadmin.vbs" 
    exit /B 
:gotAdmin 
    if exist "%temp%\getadmin.vbs" (del "%temp%\getadmin.vbs") 
    pushd "%CD%" 
    CD /D "%~dp0" 
:-------------------------------------- 
@echo off 
:SSID 
set /P inputA="Input desired Network SSID:" 
echo. 
set /P c=Is %inputA% correct? [Y/N]? 
echo. 
if /I "%c%" EQU "Y" goto :PSWD 
if /I "%c%" EQU "N" goto :SSID 
:PSWD 
set /P inputB="Input desired 8 to 63 character Network Password:" 
echo. 
set /P c=Is %inputB% correct? [Y/N]? 
echo. 
if /I "%c%" EQU "Y" goto :SETUP 
if /I "%c%" EQU "N" goto :PSWD 
:SETUP 
netsh wlan set hostednetwork mode=allow ssid=%inputA% key=%inputB% >NUL 
@echo Creating Network... 
echo. 
timeout /t 5 /nobreak > NUL 
@echo Network Created! 
echo. 
timeout /t 1 /nobreak > NUL 
set /P c=Would you like to start your new Network? [Press "Y" to continue/Press "N" to abort] 
if /I "%c%" EQU "Y" goto :START 
if /I "%c%" EQU "N" goto :BYE 
:START 
netsh wlan start hostednetwork 
timeout /t 5 /nobreak > NUL 
@echo Your Network has started! 
pause 
:BYE 
Exit 
+6

[選択](http://ss64.com/nt/choice.html)あなたの質問に答え – Stephan

+0

簡単なGoogle検索で簡単に見つけられました。次回はさらに研究をしてください。 –

+0

@MatthewHorvathこのテーマ(私はオンラインで見つけて理解していない断片的な自己指導/適応コード)に関する私の教育で、関連情報は容易に認識されません。 – Red

答えて

1

代わりのset /pを使用して、choiceコマンドを使用します。私は、個人的に、使用します。

choice /m Correct? 
if %errorlevel% equ 1 goto PSWD 
if %errorlevel% equ 2 goto SSID 

この意志表示:Continue? [Y/N]?を。ヒットした場合は:PSWDになります。彼らがnを押すと、それは:SSIDに行きます。

選択コマンドのヘルプセクション(choice /?でコマンドプロンプトで育っ)

CHOICE [/C choices] [/N] [/CS] [/T timeout /D choice] [/M text] 

Description: 
    This tool allows users to select one item from a list 
    of choices and returns the index of the selected choice. 

Parameter List: 
    /C choices  Specifies the list of choices to be created. 
         Default list is "YN". 

    /N     Hides the list of choices in the prompt. 
         The message before the prompt is displayed 
         and the choices are still enabled. 

    /CS     Enables case-sensitive choices to be selected. 
         By default, the utility is case-insensitive. 

    /T timeout  The number of seconds to pause before a default 
         choice is made. Acceptable values are from 0 to 
         9999. If 0 is specified, there will be no pause 
         and the default choice is selected. 

    /D choice  Specifies the default choice after nnnn seconds. 
         Character must be in the set of choices specified 
         by /C option and must also specify nnnn with /T. 

    /M text   Specifies the message to be displayed before 
         the prompt. If not specified, the utility 
         displays only a prompt. 

    /?     Displays this help message. 

    NOTE: 
    The ERRORLEVEL environment variable is set to the index of the 
    key that was selected from the set of choices. The first choice 
    listed returns a value of 1, the second a value of 2, and so on. 
    If the user presses a key that is not a valid choice, the tool 
    sounds a warning beep. If tool detects an error condition, 
    it returns an ERRORLEVEL value of 255. If the user presses 
    CTRL+BREAK or CTRL+C, the tool returns an ERRORLEVEL value 
    of 0. When you use ERRORLEVEL parameters in a batch program, list 
    them in decreasing order. 

Examples: 
    CHOICE /? 
    CHOICE /C YNC /M "Press Y for Yes, N for No or C for Cancel." 
    CHOICE /T 10 /C ync /CS /D y 
    CHOICE /C ab /M "Select a for option 1 and b for option 2." 
    CHOICE /C ab /N /M "Select a for option 1 and b for option 2." 
+0

助けていただきありがとうございました。 – Red

関連する問題