Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- Set This_File=%~0
- :decide
- cls
- ECHO Enter Option1 or Option2
- Call :Get_Input label YourTitle YourMessage
- Call :TestLabel decide
- ECHO disallowed,banned,restricted>"%temp%\labelnametest.txt"
- Call :RestrictLabel decide
- GOTO decide
- :option1
- ECHO Option 1
- pause
- goto decide
- :option2
- ECHO Option 2
- pause
- goto decide
- :banned
- ECHO Shouldn't Be Here
- pause
- goto decide
- :disallowed
- ECHO Shouldn't Be Here
- pause
- goto decide
- :restricted
- ECHO Shouldn't Be Here
- pause
- goto decide
- :exit
- IF EXIST "%temp%\labelnametest.txt" (
- DEL /Q ""%temp%\labelnametest.txt""
- )
- exit
- :TestLabel
- IF EXIST "%temp%\labelnametest.txt" (
- DEL /Q "%temp%\labelnametest.txt"
- )
- FIND /I ":%label%" "%This_File%" >nul
- IF ERRORLEVEL ==1 ECHO Invalid Option! && Timeout 1 >nul && GOTO %1
- GOTO :EOF
- :RestrictLabel
- FIND /I "%label%" "%temp%\labelnametest.txt" >nul
- IF ERRORLEVEL ==1 (
- goto %label% 2>nul
- ) else (
- ECHO Disallowed! && Timeout 1 >nul && GOTO %1
- )
- GOTO :EOF
- :Get_Input
- ::: Using this Function:
- ::: CALL :Get_Input YourVariable YourTitle YourMessage
- ::: Assign the variable (Passed by call Argument) to be set and tested
- SET "Fetch_Variable=%~1"
- SET "My_Title=%~2"
- SET "My_Message=%~3"
- ::: Ensure Undefined Value for Input
- SET input=
- :main
- ::: Exit Filter once Acceptable Variable is Set
- IF DEFINED input GOTO return
- ::: Create and start VBS script to Launch an Input Box and Store the input to text file for retrieval from this Batch program.
- (
- ECHO Dim objFSO 'File System Object
- ECHO Set objFSO = CreateObject("Scripting.FileSystemObject"^)
- ECHO Dim objTS 'Text Stream Object
- ECHO Const ForWriting = 2
- ECHO Set objTS = objFSO.OpenTextFile("%temp%\inputTest.txt", ForWriting, True^)
- ECHO objTS.Write(InputBox("%My_Message%","%My_Title%","Enter %Fetch_Variable%"^)^)
- ECHO objTS.Close(^)
- ECHO Set bjFSO = Nothing 'Destroy the object.
- ECHO Set objTS = Nothing 'Destroy the object.
- ) >"%temp%\GetInput.vbs"
- START /wait %temp%\GetInput.vbs
- ::: Start /wait required to hold the batch until input is returned
- :loadinput
- ::: Insist on user Input prior to attempting to load input.
- IF NOT EXIST "%temp%\inputTest.txt" GOTO invInput
- <%temp%\inputTest.txt (
- SET /P input=
- )
- ::: Test to ensure Variable defined. Needed here to prevent environment variable not defined message ahead of next test Should the variable not be defined.
- IF NOT DEFINED input GOTO invInput
- ::: Test for Doublequotes and reset variable if present
- SET Input | FIND """" >NUL
- IF NOT ERRORLEVEL 1 SET Input=
- IF NOT DEFINED input GOTO invInput
- SET Input | FIND "~" >NUL
- IF NOT ERRORLEVEL 1 SET Input=
- IF NOT DEFINED input GOTO invInput
- ::: Test for Spaces (REM out if not required)
- IF NOT "%input%"=="%input: =%" GOTO invInput
- ::: Test for all other standard Symbols. (REM out any you wish to permit)
- IF NOT "%input%"=="%input:&=%" GOTO invInput
- IF NOT "%input%"=="%input:(=%" GOTO invInput
- IF NOT "%input%"=="%input:)=%" GOTO invInput
- IF NOT "%input%"=="%input:<=%" GOTO invInput
- IF NOT "%input%"=="%input:>=%" GOTO invInput
- IF NOT "%input%"=="%input:{=%" GOTO invInput
- IF NOT "%input%"=="%input:}=%" GOTO invInput
- IF NOT "%input%"=="%input:]=%" GOTO invInput
- IF NOT "%input%"=="%input:[=%" GOTO invInput
- IF NOT "%input%"=="%input:#=%" GOTO invInput
- IF NOT "%input%"=="%input:^=%" GOTO invInput
- IF NOT "%input%"=="%input:+=%" GOTO invInput
- IF NOT "%input%"=="%input:-=%" GOTO invInput
- IF NOT "%input%"=="%input:/=%" GOTO invInput
- IF NOT "%input%"=="%input:\=%" GOTO invInput
- IF NOT "%input%"=="%!!|%" GOTO invInput
- IF NOT "%input%"=="%input:$=%" GOTO invInput
- IF NOT "%input%"=="%input:!=%" GOTO invInput
- IF NOT "%input%"=="%input:?=%" GOTO invInput
- IF NOT "%input%"=="%input:@=%" GOTO invInput
- IF NOT "%input%"=="%input:'=%" GOTO invInput
- IF NOT "%input%"=="%input:,=%" GOTO invInput
- IF NOT "%input%"=="%input:.=%" GOTO invInput
- IF NOT "%input%"=="%!!%" GOTO invInput
- IF NOT "%input%"=="%input:`=%" GOTO invInput
- GOTO main
- :invInput
- SET input=
- IF EXIST "%temp%\GetInput.vbs" (
- DEL /Q "%temp%\GetInput.vbs"
- )
- GOTO main
- :return
- ::: assigns the input value to the variable name being validated.
- SET %Fetch_Variable%=%input%
- SET input=
- IF EXIST "%temp%\inputTest.txt" (
- DEL /Q "%temp%\inputTest.txt"
- )
- IF EXIST "%temp%\GetInput.vbs" (
- DEL /Q "%temp%\GetInput.vbs"
- )
- GOTO :EOF
Advertisement
Add Comment
Please, Sign In to add comment