how to run cmd command netsh using notepad - windows

I want to make autorun .bat program that automatically performs netsh cmd and save the result in .txt file by the just simple click of a button.
below is what I wrote in notepad and saved as getkey.bat
echo netsh wlan show profile name=wifi_name key=clear >Desktop/savedpasskey.txt
exit
but it is not working

To show the password of your WIFI SSID , you must execute this batch file with admin rights :
#echo off & setlocal enabledelayedexpansion
Set "Copyright=by Hackoo 2017"
Title %~n0 %Copyright%
Mode con cols=75 lines=8
cls & color 0A & echo.
echo ***********************************************
echo %~n0 %Copyright%
echo ***********************************************
echo(
if _%1_==_Main_ goto :Main
Set Count=0
Set L=0
:getadmin
echo %~nx0 : self elevating
set vbs=%temp%\getadmin.vbs
(
echo Set UAC = CreateObject^("Shell.Application"^)
echo UAC.ShellExecute "%~s0", "Main %~sdp0 %*", "", "runas", 1
)> "%vbs%"
"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
goto :eof
::*************************************************************************************
:Main
Call :init
Call :CountLines
Set "PasswordLog=%~dp0Wifi_Passwords_on_%ComputerName%.txt"
%Mod%
echo(
echo ***********************************************
echo %~n0 %Copyright%
echo ***********************************************
echo(
Call :Color 0E " [N][SSID] ================ Password" 1
echo(
(
echo ***********************************************
echo %~n0 %Copyright%
echo ***********************************************
echo(
echo [N][SSID] ==============^> "Password"
echo(
)>"%PasswordLog%"
for /f "skip=2 delims=: tokens=2" %%a in ('netsh wlan show profiles') do (
if not "%%a"=="" (
set "ssid=%%a"
set "ssid=!ssid:~1!"
call :Getpassword "!ssid!"
)
)
echo(
echo Done
If exist "%PasswordLog%" start "" "%PasswordLog%"
pause>nul
exit
::*************************************************************************************
:Getpassword
set "name=%1"
set "name=!name:"=!"
Set "passwd="
for /f "delims=: tokens=2" %%a in ('netsh wlan show profiles %1 key^=clear ^|find /I "Cont"') do (
set "passwd=%%a"
Set /a Count+=1
)
If defined passwd (
set passwd=!passwd:~1!
echo [!Count!][!name!] ====^> "!passwd!"
echo [!Count!][!name!] ====^> "!passwd!" >> "%PasswordLog%"
) else (
Set /a Count+=1
call :color 0C " [!Count!][!name!] The Password is empty" 1
echo [!Count!][!name!] The Password is empty >> "%PasswordLog%"
)
exit /b
::*************************************************************************************
:init
prompt $g
for /F "delims=." %%a in ('"prompt $H. & for %%b in (1) do rem"') do set "BS=%%a"
exit /b
::*************************************************************************************
:color
set nL=%3
if not defined nL echo requires third argument & pause > nul & goto :eof
if %3 == 0 (
<nul set /p ".=%bs%">%2 & findstr /v /a:%1 /r "^$" %2 nul & del %2 2>&1 & goto :eof
) else if %3 == 1 (
echo %bs%>%2 & findstr /v /a:%1 /r "^$" %2 nul & del %2 2>&1 & goto :eof
)
exit /b
::*************************************************************************************
:CountLines
for /f "skip=2 delims=: tokens=2" %%a in ('netsh wlan show profiles') do (
if not "%%a"=="" (
set /a L+=1
)
)
set /a L=!L! + 10
Set Mod=Mode con cols=75 Lines=!L!
exit /b
::*************************************************************************************

This works. You can change the TEMPFILE to wherever you want the file to be created.
SET "TEMPFILE=%USERPROFILE%\Desktop\savedpasskey.txt"
netsh wlan show profile name=wifi_name key=clear >"%TEMPFILE%"
TYPE "%TEMPFILE%"

It was not working because the path you specified to save your output text file was not getting recognized. The below code should work properly.
#echo off
netsh wlan show profile name=wifi_name key=clear >%USERPROFILE%\Desktop\savedpasskey.txt
#pause
It's always better to specify fully qualified path for the files. In this case it will be C:\Users\<User_Name>\Desktop\savedpasskey.txt where %USERPROFILE% will been replaced with C:\Users\<User_Name>.
Remove #pause if you don't want the command prompt to stay on screen after command is executed.

Related

Filter results in batch script for user printer selection

I am trying to create a script to allow users to temporarily set the default windows printer to a selected printer (PDF, XPS, OneNote) before printing and then automatically set the default back to the original printer after a specified time.
I have managed to incorporate elements of many different examples to get to the stage where the script is functioning, although it is creating an extra entry at the start and end of the list.
I would like to filter the list of printers the user is shown to just ones from the appropriate list (e.g. PDF, XPS, OneNote).
Any help would be greatly appreciated.
#echo off
setlocal enableDelayedExpansion
FOR /F "tokens=2* delims==" %%A in (
'wmic printer where "default=True" get name /value'
) do SET DefaultPrinter=%%A
ECHO.
ECHO ==============================================================
ECHO Current Default Printer
ECHO ==============================================================
ECHO.
ECHO Default Printer = %DefaultPrinter%
ECHO.
pause
Cls
ECHO ==============================================================
ECHO Processing locally installed printers
ECHO ==============================================================
::build "array" of printers
set printerCnt=0
for /f "eol=: delims=" %%F in ('wmic printer get Name') do (
set /a printerCnt+=1
set "printer!printerCnt!=%%F"
)
::print menu
for /l %%N in (1 1 %printerCnt%) do echo %%N - !printer%%N!
echo(
:get selection
set selection=
set /p "selection=Enter a printer number: "
echo You picked !printer%selection%!
set NewPrinter=!printer%selection%!
::trim selection
set str=%NewPrinter%
for /l %%a in (1,1,31) do if "!str:~-1!"==" " set str=!str:~0,-1!
RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n "%str%"
TIMEOUT 10
RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n "%DefaultPrinter%"
[Edit /]
I have included the code I ended up using. This was based on the answer provided by #Hackoo and I incorporated elements provided by #Magoo also. There is probably a more elegant way to write this code but I am new to this so laid it out as I understood it.
#echo off
Mode 70,30 & color F0
Title Healthmail Printer Selection
FOR /F "tokens=2* delims==" %%A in (
'wmic printer where "default=True" get name /value'
) do SET "DefaultPrinter=%%A"
ECHO.
ECHO ==============================================================
ECHO Current Default Printer
ECHO ==============================================================
ECHO.
ECHO Default Printer = [%DefaultPrinter%]
ECHO.
TIMEOUT /T 2 /NoBreak>nul
Cls
ECHO.
ECHO ==============================================================
ECHO Available Printers
ECHO ==============================================================
Setlocal EnableDelayedExpansion
::build "array" of printers
Set "FilterList=%Temp%\FilterList.txt"
REM Create a file to filter just for PDF printers
>"%FilterList%" (
echo PDF
)
set printerCnt=0
#for /f "delims=" %%a in (
'wmic printer get Name ^|findstr /G:%FilterList%"'
) do (
#for /f "delims=" %%b in ("%%a") do (
set /a printerCnt+=1
set "printer!printerCnt!=%%~nb"
)
)
::If no printers have been found, go to filterlistlong
:zerofilterprinters
IF !printerCnt!==0 GOTO :filterlistlong
IF !printerCnt! gtr 0 GOTO :printmenu
:filterlistlong
Set "FilterListLong=%Temp%\FilterListLong.txt"
REM Create a file to filter with each word like XPS,OneNote and PDF
>"%FilterListLong%" (
echo PDF
echo XPS
echo OneNote
)
set printerCnt=0
#for /f "delims=" %%a in (
'wmic printer get Name ^|findstr /G:%FilterListLong%"'
) do (
#for /f "delims=" %%b in ("%%a") do (
set /a printerCnt+=1
set "printer!printerCnt!=%%~nb"
)
)
:printmenu
SET "choices="
for /l %%N in (1 1 %printerCnt%) do SET "choices=!choices!%%N"&SET "printer%%N=!printer%%N!"&IF %printercnt% gtr 1 echo %%N - !printer%%N!
echo(
:get selection
:: If no available options, exit
IF NOT DEFINED choices GOTO :EOF
:: If only 1 option, auto-select that
IF %choices%==1 SET /a selection=1&GOTO autoselect
choice /c %choices% /m "Enter a printer number: "
set selection=%ERRORLEVEL%
:: Error condition
IF %selection% gtr %printercnt% GOTO :EOF
:: Control-C
IF %selection% equ 0 GOTO :EOF
cls
ECHO ==============================================================
ECHO You selected: !printer%selection%!
ECHO ==============================================================
echo.
echo. Please proceed to print document.
echo.
echo. This window will close automatically in 30 seconds.
::GOTO :setprinter
:autoselect
set NewPrinter=!printer%selection%!
cls
ECHO ==============================================================
ECHO Printer selected: !printer%selection%!
ECHO ==============================================================
echo.
echo. Please proceed to print document.
echo.
echo. This window will close automatically in 10 seconds.
:setprinter
RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n "%NewPrinter%"
TIMEOUT /T 10 /nobreak > NUL
RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n "%DefaultPrinter%"
GOTO :EOF
If Exist "%FilterList%" Del "%FilterList%"
If Exist "%FilterListLong%" Del "%FilterListLong%"
The output of WMIC is unicode !
The trailing <CR> can be removed by passing the value through another FOR /F loop.
This also removes the phantom "blank" line (actually a <CR>) and in this case you don't need to use the Trim function !
#echo off
Mode 70,30 & color 0A
Title Filter results in batch script for user printer selection
FOR /F "tokens=2* delims==" %%A in (
'wmic printer where "default=True" get name /value'
) do SET "DefaultPrinter=%%A"
ECHO.
ECHO ==============================================================
ECHO Current Default Printer
ECHO ==============================================================
ECHO.
ECHO Default Printer = [%DefaultPrinter%]
ECHO.
TIMEOUT /T 3 /NoBreak>nul
Cls
ECHO.
ECHO ==============================================================
ECHO Processing locally installed printers
ECHO ==============================================================
Setlocal EnableDelayedExpansion
::build "array" of printers
REM We Ignore printer begin with Micro or Fax in the name
Set "FilterList=%Temp%\FilterList.txt"
REM We create a file to filter with each word like XPS,OneNote and PDF
>"%FilterList%" (
echo XPS
echo OneNote
echo PDF
)
set printerCnt=0
#for /f "skip=1 delims=" %%a in (
'wmic printer get Name ^|findstr /G:%FilterList%"'
) do (
#for /f "delims=" %%b in ("%%a") do (
set /a printerCnt+=1
set "printer!printerCnt!=%%~nb"
)
)
::print menu
for /l %%N in (1 1 %printerCnt%) do echo [%%N] - [!printer%%N!]
echo ==============================================================
:get selection
set selection=
set /p "selection=Enter a printer number: "
set "NewPrinter=!printer%selection%!"
echo. You picked [%NewPrinter%]
RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n "%NewPrinter%"
TIMEOUT /T 10
RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n "%DefaultPrinter%"
If Exist "%FilterList%" Del "%FilterList%"
#echo off
setlocal ENABLEDELAYEDEXPANSION
SET "printfilter=%1"
FOR /F "tokens=2* delims==" %%A in (
'wmic printer where "default=True" get name /value'
) do SET DefaultPrinter=%%A
ECHO.
ECHO ==============================================================
ECHO Current Default Printer
ECHO ==============================================================
ECHO.
ECHO Default Printer = %DefaultPrinter%
ECHO.
pause
Cls
ECHO ==============================================================
ECHO Processing locally installed printers
ECHO ==============================================================
::build "array" of printers
set printerCnt=0
for /f "skip=1eol=: delims=" %%F in ('wmic printer get Name') do (
set /a printerCnt+=1
set "printer!printerCnt!=%%F"
IF DEFINED printfilter ECHO %%F|FIND /i "%printfilter%" >nul&IF ERRORLEVEL 1 SET /a printercnt-=1
)
iF NOT DEFINED printfilter (
set "printer%printerCnt%="
SET /a printercnt-=1
)
::print menu
SET "choices="
for /l %%N in (1 1 %printerCnt%) do SET "choices=!choices!%%N"&SET "printer%%N=!printer%%N:~0,-1!"&IF %printercnt% gtr 1 echo %%N - !printer%%N!
echo(
:get selection
:: If no available options, exit
IF NOT DEFINED choices GOTO :EOF
:: If only 1 option, auto-select that
IF %choices%==1 SET /a selection=1&GOTO autoselect
choice /c %choices% /m "Enter a printer number: "
set selection=%ERRORLEVEL%
:: Error condition
IF %selection% gtr %printercnt% GOTO :EOF
:: Control-C
IF %selection% equ 0 GOTO :EOF
echo You picked !printer%selection%!
:autoselect
set NewPrinter=!printer%selection%!
::trim selection
set str=%NewPrinter%
for /l %%a in (1,1,31) do if "!str:~-1!"==" " set str=!str:~0,-1!
ECHO RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n "%str%"
ECHO TIMEOUT 10
ECHO RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n "%DefaultPrinter%"
GOTO :EOF
Amusing...
First, to specify the filter, simply append an appropriate string (PDF, XPS, OneNote) to the batchname as a parameter. Omitting this selects ALL.
First step is to add the skip=1 to the for /f ... %%F... so that the Name line from the report is skipped.
Next, if the filter is invoked, detect whether the printername includes the filter string. If it does NOT, then back up the printer-counter.
Having built the array, noting that the last (bogus) entry will have been recorded UNLESS the filter is invoked, clear the last (bogus) entry and back up the counter.
The point with WMIC output is that it's not only Unicode, but it has a line-terminator of <CR><CR><LF> instead of <CR><LF>. The text values stored in the array each have a terminal <CR>. Hence the bogus last entry.
So, for each entry passing the filter, build a string of the options allowed into choices, and remove the last character from the printer name string and show it.
Now if there are no choices, exit (or something else).
If there's only one choice, auto-select it (and don't show the selection-list) Otherwise use choice to select the printers from the list.
You'd need to add to the list of choices to allow selection of printers beyond #9.
and I chose to simply echo the rundll32s and timeout for testing.
I'd just enumerate the printers once, and get rid of much of the unnecessary screen output:
#Echo Off
SetLocal EnableExtensions DisableDelayedExpansion
Set "SysDir=%SystemRoot%\System32"
For /F "Delims==" %%G In ('"(Set Printer[) 2>NUL"') Do Set "%%G="
Set "DefaultPrinter="
For /F "Tokens=1-3,* Delims=[,]" %%G In ('%SysDir%\wbem\WMIC.exe Printer Get
Default^, Name /Format:CSV 2^>NUL ^| %SysDir%\findstr.exe "E\>" ^|
%SysDir%\find.exe /V /N ""') Do For /F "Tokens=*" %%K In ("%%J") Do (
Echo([%%G] %%K
If "%%I" == "TRUE" Set "DefaultPrinter=%%K"
Set "Printer[%%G]=%%K")
If Not Defined Printer[1] (Echo No printers found.
Echo Press any key to end . . .
GoTo :EOF)
Echo(
(Set DefaultPrinter) 2>NUL || Echo No default printer found.
:Selection
Echo(
Set "UserPrinter="
Set /P "UserPrinter=Enter the number for your preferred printer>"
Set "UserPrinter=%UserPrinter:"=%"
Set Printer[ | %SysDir%\findstr.exe /B /L "Printer[%UserPrinter%]=" 1>NUL || (
GoTo Selection)
SetLocal EnableDelayedExpansion
For %%G In ("!Printer[%UserPrinter%]!") Do EndLocal & Set "UserPrinter=%%~G"
Echo(
Echo You Selected %UserPrinter%
%SysDir%\timeout.exe /T 3 /NoBreak 1>NUL
%SysDir%\rundll32.exe %SysDir%\printui.dll,PrintUIEntry /y /n "%UserPrinter%"
%SysDir%\timeout.exe /T 10
%SysDir%\rundll32.exe %SysDir%\printui.dll,PrintUIEntry /y /n "%DefaultPrinter%"
[EDIT /]
If you really do need to support windows-7, and windows-server-2008-r2, and you cannot guarantee that the XSL files have been copied up a level on the target machine, then it should still possible. Although it looks like a lot of extra lines, the following example should not seriously impact your script speed, other than the extra call to the relatively slow WMIC.exe, (your example, as well as the other currently submitted answers, already use more than one WMIC command).
#Echo Off
SetLocal EnableExtensions DisableDelayedExpansion
Set "SysDir=%SystemRoot%\System32"
%SysDir%\wbem\WMIC.exe OS Where "Version Like '6.1%%'" Get Version 2>NUL ^
| %SysDir%\find.exe "6.1" 1>NUL && Call :GetXSLDir
For /F "Delims==" %%G In ('"(Set Printer[) 2>NUL"') Do Set "%%G="
Set "DefaultPrinter="
For /F "Tokens=1-3,* Delims=[,]" %%G In ('%SysDir%\wbem\WMIC.exe Printer Get
Default^, Name /Format:"%XSLDir%csv.xsl" 2^>NUL ^| %SysDir%\findstr.exe "E\>"
^| %SysDir%\find.exe /V /N ""') Do For /F "Tokens=*" %%K In ("%%J") Do (
Echo([%%G] %%K
If "%%I" == "TRUE" Set "DefaultPrinter=%%K"
Set "Printer[%%G]=%%K")
If Not Defined Printer[1] (Echo No printers found.
Echo Press any key to end . . .
GoTo :EOF)
Echo(
(Set DefaultPrinter) 2>NUL || Echo No default printer found.
:Selection
Echo(
Set "UserPrinter="
Set /P "UserPrinter=Enter the number for your preferred printer>"
Set "UserPrinter=%UserPrinter:"=%"
Set Printer[ | %SysDir%\findstr.exe /B /L "Printer[%UserPrinter%]=" 1>NUL || (
GoTo Selection)
SetLocal EnableDelayedExpansion
For %%G In ("!Printer[%UserPrinter%]!") Do EndLocal & Set "UserPrinter=%%~G"
Echo(
Echo You Selected %UserPrinter%
%SysDir%\timeout.exe /T 3 /NoBreak 1>NUL
%SysDir%\rundll32.exe %SysDir%\printui.dll,PrintUIEntry /y /n "%UserPrinter%"
%SysDir%\timeout.exe /T 10
%SysDir%\rundll32.exe %SysDir%\printui.dll,PrintUIEntry /y /n "%DefaultPrinter%"
GoTo :EOF
:GetXSLDir
For %%G In (Default InstallLanguage XSLDir) Do Set "%%G="
For /F "Tokens=1,2*" %%G In ('%SysDir%\reg.exe Query
HKLM\System\CurrentControlSet\Control\Nls\Language 2^>NUL ^|
%SysDir%\findstr.exe /I "\<Default\> \<InstallLanguage\>"'
) Do For /F "Tokens=2 Delims=:" %%J In ('%SysDir%\findstr.exe "::%%I:" "%~f0"'
) Do Set "%%G=%%J"
If Exist "%SysDir%\wbem\%Default%\*.xsl" (Set "XSLDir=%SysDir%\wbem\%Default%\"
) Else If Exist "%SysDir%\wbem\%InstallLanguage%\*.xsl" (
Set "XSLDir=%SysDir%\wbem\%InstallLanguage%\")
For %%G In (Default InstallLanguage) Do Set "%%G="
Exit /B
::0001:ar
::0002:bg
::0003:ca
::0004:zh-Hans
::0005:cs
::0006:da
::0007:de
::0008:el
::0009:en
::000A:es
::000B:fi
::000C:fr
::000D:he
::000E:hu
::000F:is
::0010:it
::0011:ja
::0012:ko
::0013:nl
::0014:no
::0015:pl
::0016:pt
::0017:rm
::0018:ro
::0019:ru
::001A:hr
::001B:sk
::001C:sq
::001D:sv
::001E:th
::001F:tr
::0020:ur
::0021:id
::0022:uk
::0023:be
::0024:sl
::0025:et
::0026:lv
::0027:lt
::0028:tg
::0029:fa
::002A:vi
::002B:hy
::002C:az
::002D:eu
::002E:hsb
::002F:mk
::0030:st
::0031:ts
::0032:tn
::0033:ve
::0034:xh
::0035:zu
::0036:af
::0037:ka
::0038:fo
::0039:hi
::003A:mt
::003B:se
::003C:ga
::003D:yi
::003E:ms
::003F:kk
::0040:ky
::0041:sw
::0042:tk
::0043:uz
::0044:tt
::0045:bn
::0046:pa
::0047:gu
::0048:or
::0049:ta
::004A:te
::004B:kn
::004C:ml
::004D:as
::004E:mr
::004F:sa
::0050:mn
::0051:bo
::0052:cy
::0053:km
::0054:lo
::0055:my
::0056:gl
::0057:kok
::0058:mni
::0059:sd
::005A:syr
::005B:si
::005C:chr
::005D:iu
::005E:am
::005F:tzm
::0060:ks
::0061:ne
::0062:fy
::0063:ps
::0064:fil
::0065:dv
::0066:bin
::0067:ff
::0068:ha
::0069:ibb
::006A:yo
::006B:quz
::006C:nso
::006D:ba
::006E:lb
::006F:kl
::0070:ig
::0071:kr
::0072:om
::0073:ti
::0074:gn
::0075:haw
::0076:la
::0077:so
::0078:ii
::0079:pap
::007A:arn
::007C:moh
::007E:br
::0080:ug
::0081:mi
::0082:oc
::0083:co
::0084:gsw
::0085:sah
::0086:qut
::0087:rw
::0088:wo
::008C:prs
::0091:gd
::0092:ku
::0093:quc
::0401:ar-SA
::0402:bg-BG
::0403:ca-ES
::0404:zh-TW
::0405:cs-CZ
::0406:da-DK
::0407:de-DE
::0408:el-GR
::0409:en-US
::040A:es-ES_tradnl
::040B:fi-FI
::040C:fr-FR
::040D:he-IL
::040E:hu-HU
::040F:is-IS
::0410:it-IT
::0411:ja-JP
::0412:ko-KR
::0413:nl-NL
::0414:nb-NO
::0415:pl-PL
::0416:pt-BR
::0417:rm-CH
::0418:ro-RO
::0419:ru-RU
::041A:hr-HR
::041B:sk-SK
::041C:sq-AL
::041D:sv-SE
::041E:th-TH
::041F:tr-TR
::0420:ur-PK
::0421:id-ID
::0422:uk-UA
::0423:be-BY
::0424:sl-SI
::0425:et-EE
::0426:lv-LV
::0427:lt-LT
::0428:tg-Cyrl-TJ
::0429:fa-IR
::042A:vi-VN
::042B:hy-AM
::042C:az-Latn-AZ
::042D:eu-ES
::042E:hsb-DE
::042F:mk-MK
::0430:st-ZA
::0431:ts-ZA
::0432:tn-ZA
::0433:ve-ZA
::0434:xh-ZA
::0435:zu-ZA
::0436:af-ZA
::0437:ka-GE
::0438:fo-FO
::0439:hi-IN
::043A:mt-MT
::043B:se-NO
::043D:yi-Hebr
::043E:ms-MY
::043F:kk-KZ
::0440:ky-KG
::0441:sw-KE
::0442:tk-TM
::0443:uz-Latn-UZ
::0444:tt-RU
::0445:bn-IN
::0446:pa-IN
::0447:gu-IN
::0448:or-IN
::0449:ta-IN
::044A:te-IN
::044B:kn-IN
::044C:ml-IN
::044D:as-IN
::044E:mr-IN
::044F:sa-IN
::0450:mn-MN
::0451:bo-CN
::0452:cy-GB
::0453:km-KH
::0454:lo-LA
::0455:my-MM
::0456:gl-ES
::0457:kok-IN
::0458:mni-IN
::0459:sd-Deva-IN
::045A:syr-SY
::045B:si-LK
::045C:chr-Cher-US
::045D:iu-Cans-CA
::045E:am-ET
::045F:tzm-Arab-MA
::0460:ks-Arab
::0461:ne-NP
::0462:fy-NL
::0463:ps-AF
::0464:fil-PH
::0465:dv-MV
::0466:bin-NG
::0467:fuv-NG
::0468:ha-Latn-NG
::0469:ibb-NG
::046A:yo-NG
::046B:quz-BO
::046C:nso-ZA
::046D:ba-RU
::046E:lb-LU
::046F:kl-GL
::0470:ig-NG
::0471:kr-NG
::0472:om-ET
::0473:ti-ET
::0474:gn-PY
::0475:haw-US
::0476:la-Latn
::0477:so-SO
::0478:ii-CN
::0479:pap-029
::047A:arn-CL
::047C:moh-CA
::047E:br-FR
::0480:ug-CN
::0481:mi-NZ
::0482:oc-FR
::0483:co-FR
::0484:gsw-FR
::0485:sah-RU
::0486:qut-GT
::0487:rw-RW
::0488:wo-SN
::048C:prs-AF
::048D:plt-MG
::048E:zh-yue-HK
::048F:tdd-Tale-CN
::0490:khb-Talu-CN
::0491:gd-GB
::0492:ku-Arab-IQ
::0493:quc-CO
::0501:qps-ploc
::05FE:qps-ploca
::0801:ar-IQ
::0803:ca-ES-valencia
::0804:zh-CN
::0807:de-CH
::0809:en-GB
::080A:es-MX
::080C:fr-BE
::0810:it-CH
::0811:ja-Ploc-JP
::0813:nl-BE
::0814:nn-NO
::0816:pt-PT
::0818:ro-MD
::0819:ru-MD
::081A:sr-Latn-CS
::081D:sv-FI
::0820:ur-IN
::082C:az-Cyrl-AZ
::082E:dsb-DE
::0832:tn-BW
::083B:se-SE
::083C:ga-IE
::083E:ms-BN
::083F:kk-Latn-KZ
::0843:uz-Cyrl-UZ
::0845:bn-BD
::0846:pa-Arab-PK
::0849:ta-LK
::0850:mn-Mong-CN
::0851:bo-BT
::0859:sd-Arab-PK
::085D:iu-Latn-CA
::085F:tzm-Latn-DZ
::0860:ks-Deva
::0861:ne-IN
::0867:ff-Latn-SN
::086B:quz-EC
::0873:ti-ER
::09FF:qps-plocm
::0C01:ar-EG
::0C04:zh-HK
::0C07:de-AT
::0C09:en-AU
::0C0A:es-ES
::0C0C:fr-CA
::0C1A:sr-Cyrl-CS
::0C3B:se-FI
::0C50:mn-Mong-MN
::0C51:dz-BT
::0C5F:tmz-MA
::0C6b:quz-PE
::1001:ar-LY
::1004:zh-SG
::1007:de-LU
::1009:en-CA
::100A:es-GT
::100C:fr-CH
::101A:hr-BA
::103B:smj-NO
::105F:tzm-Tfng-MA
::1401:ar-DZ
::1404:zh-MO
::1407:de-LI
::1409:en-NZ
::140A:es-CR
::140C:fr-LU
::141A:bs-Latn-BA
::143B:smj-SE
::1801:ar-MA
::1809:en-IE
::180A:es-PA
::180C:fr-MC
::181A:sr-Latn-BA
::183B:sma-NO
::1C01:ar-TN
::1C09:en-ZA
::1C0A:es-DO
::1C1A:sr-Cyrl-BA
::1C3B:sma-SE
::2001:ar-OM
::2009:en-JM
::200A:es-VE
::200C:fr-RE
::201A:bs-Cyrl-BA
::203B:sms-FI
::2401:ar-YE
::2409:en-029
::240A:es-CO
::240C:fr-CD
::241A:sr-Latn-RS
::243B:smn-FI
::2801:ar-SY
::2809:en-BZ
::280A:es-PE
::280C:fr-SN
::281A:sr-Cyrl-RS
::2C01:ar-JO
::2C09:en-TT
::2C0A:es-AR
::2C0C:fr-CM
::2C1A:sr-Latn-ME
::3001:ar-LB
::3009:en-ZW
::300A:es-EC
::300C:fr-CI
::301A:sr-Cyrl-ME
::3401:ar-KW
::3409:en-PH
::340A:es-CL
::340C:fr-ML
::3801:ar-AE
::3809:en-ID
::380A:es-UY
::380C:fr-MA
::3c01:ar-BH
::3c09:en-HK
::3c0A:es-PY
::3c0C:fr-HT
::4001:ar-QA
::4009:en-IN
::400A:es-BO
::4401:ar-Ploc-SA
::4409:en-MY
::440A:es-SV
::4801:ar-145
::4809:en-SG
::480A:es-HN
::4C09:en-AE
::4C0A:es-NI
::5009:en-BH
::500A:es-PR
::5409:en-EG
::540A:es-US
::5809:en-JO
::580A:es-419
::5C09:en-KW
::5C0A:es-CU
::6009:en-TR
::6409:en-YE
::641A:bs-Cyrl
::681A:bs-Latn
::6C1A:sr-Cyrl
::701A:sr-Latn
::703B:smn
::742C:az-Cyrl
::743B:sms
::7804:zh
::7814:nn
::781A:bs
::782C:az-Latn
::783B:sma
::783F:kk-Cyrl
::7843:uz-Cyrl
::7850:mn-Cyrl
::785D:iu-Cans
::785F:tzm-Tfng
::7C04:zh-Hant
::7C14:nb
::7C1A:sr
::7C28:tg-Cyrl
::7C2E:dsb
::7C3B:smj
::7C3F:kk-Latn
::7C43:uz-Latn
::7C46:pa-Arab
::7C50:mn-Mong
::7C59:sd-Arab
::7C5C:chr-Cher
::7C5D:iu-Latn
::7C5F:tzm-Latn
::7C67:ff-Latn
::7C68:ha-Latn
::7C92:ku-Arab
::E40C:fr-015

Color changing in windows ping

Does anyone know how to make windows pinger (.bat) to show normally green but when and only when the target of the ping is offline the color is red? I have tried this several times and never got it to work. The current script is down below. That one does not work it will just change colord rapidly.
:top
PING -n 1 %IP% | FIND "TTL="
IF ERRORLEVEL 1 (SET in=0b & color 04 & echo Connection timed out.)
IF NOT ERRORLEVEL 1 GOTO color
REM errorhandling, errorlevel >= 1
ping -t 2 0 10 127.0.0.1 >nul
GoTo top
:color
color 02
GoTo top```
Here is an example for testing :
#echo off
REM https://pastebin.com/zjYwSqUM
Title Multi-Ping hosts Tester with colors updated on 2021 by Hackoo
call :init
set "URLS=%~dp0URLS.txt"
If Not exist "%URLS%" goto CreateDummyFile
mode con cols=70 lines=35
set "LogFile=PingResults.txt"
If exist "%LogFile%" Del "%LogFile%"
echo(
call :color 0E " ------- Ping status of targets hosts -------" 1
echo(
(
echo ******************************************************
echo PingTest executed on %Date% # Time %Time%
echo ******************************************************
echo(
) > %LogFile%
Setlocal EnableDelayedExpansion
for /f "usebackq delims=" %%a in ("%URLS%") do (
Call :StringFormat "%%a"
for /f "tokens=2 delims=[]" %%b in ('ping -n 1 !URL!') do set "ip=%%b"
ping -n 1 !URL!>nul && set "msg=!URL! - !ip! ALive ok" && Call :Color 0A " !msg!" 1 || set "msg=!URL! - !ip! Dead failed to respond" && Call :Color 0C " !msg!" 1
echo !msg! >> %LogFile%
)
)
EndLocal
Start "" "%LogFile%" & TimeOut /T 5 /Nobreak>nul & exit
::*************************************************************************************
:init
prompt $g
for /F "delims=." %%a in ('"prompt $H. & for %%b in (1) do rem"') do set "BS=%%a"
exit /b
::*************************************************************************************
:color
set nL=%3
if not defined nL echo requires third argument & pause > nul & goto :eof
if %3 == 0 (
<nul set /p ".=%bs%">%2 & findstr /v /a:%1 /r "^$" %2 nul & del %2 2>&1 & goto :eof
) else if %3 == 1 (
echo %bs%>%2 & findstr /v /a:%1 /r "^$" %2 nul & del %2 2>&1 & goto :eof
)
exit /b
::*************************************************************************************
:ReplaceString <Data> <String1> <String2>
(
echo Wscript.echo Replace("%~1","%~2","%~3"^)
)>"%tmp%\%~n0.vbs"
for /f "delims=" %%a in ('Cscript /nologo "%tmp%\%~n0.vbs"') do ( set "URL=%%a" )
If Exist "%tmp%\%~n0.vbs" Del "%tmp%\%~n0.vbs"
exit /b
::*************************************************************************************
:StringFormat <URL>
(
echo Function StringReplace(Str^)
echo Str = Replace(Str,"http://",""^)
echo Str = Replace(Str,"https://",""^)
echo StringReplace = str
echo End Function
echo wscript.echo StringReplace("%~1"^)
)>"%tmp%\%~n0.vbs"
for /f "delims=" %%a in ('Cscript /nologo "%tmp%\%~n0.vbs"') do ( set "URL=%%a" )
If Exist "%tmp%\%~n0.vbs" Del "%tmp%\%~n0.vbs"
exit /b
::*************************************************************************************
:CreateDummyFile
(
echo http://www.hyperdebrid.com
echo http://www.fakirdebrid.net
echo http://www.keepfiles.fr
echo http://www.4shared.com
echo https://1fichier.com
echo http://www.mega.co.nz
echo http://www.mediafire.com
echo http://www.uploaded.net
echo http://www.oboom.com
echo http://www.letitbit.net
echo http://www.keep2share.cc
echo http://alfafile.net
echo https://www.bigfile.to
echo http://www.dailymotion.com
echo http://www.datafile.com
echo http://www.Depfile.com
echo http://www.Dropbox.com
echo http://www.Extmatrix.com
echo http://www.Fboom.me
echo http://www.Filefactory.com
echo http://www.Filesmonster.com
echo http://www.Fshare.vn
echo http://www.Keep2share.com
echo http://www.Mega.nz
echo http://www.Rapidgator.net
echo http://www.Scribd.com
echo http://www.Soundcloud.com
echo http://www.Speedyshare.com
echo http://www.Turbobit.net
echo http://www.Vimeo.com
)>%URLS%
start /b "" cmd /c "%~f0" & exit
::*************************************************************************************
EDIT : on 22/01/2021 # 12:53
#echo off
Title IP Pinger with color by Hackoo 2021
:Main
cls & echo(
echo Type the IP address for checking
Set /P "IP="
call :init
Setlocal EnableDelayedExpansion
ping -n 1 !IP! |find /I "TTL">nul && set "msg=!IP! - ALive ok" && (
Call :Color 0A "!msg!" 1
) || (
set "msg=!IP! - Dead - Failed to respond" && Call :Color 0C "!msg!" 1
)
echo(
echo Hit any key to check another IP address !
Pause>nul & goto Main
::------------------------------------------------------------------------------------
:init
prompt $g
for /F "delims=." %%a in ('"prompt $H. & for %%b in (1) do rem"') do set "BS=%%a"
exit /b
::------------------------------------------------------------------------------------
:color
set nL=%3
if not defined nL echo requires third argument & pause > nul & goto :eof
if %3 == 0 (
<nul set /p ".=%bs%">%2 & findstr /v /a:%1 /r "^$" %2 nul & del %2 2>&1 & goto :eof
) else if %3 == 1 (
echo %bs%>%2 & findstr /v /a:%1 /r "^$" %2 nul & del %2 2>&1 & goto :eof
)
exit /b
::------------------------------------------------------------------------------------
Achieved with the below
cls
echo off
:top
PING -n 1 %1 | FIND "TTL="
IF ERRORLEVEL 1 (
SET in=0b
color 04
echo Connection timed out.
GOTO top
) else (
GOTO color
)
GoTo top
:color
color 02
ping 127.0.0.1 -n 2 > nul
GoTo top
Theres many approaches you can take for this task
The two main components of the task are:
effecting a means of conditional execution based on success or failure.
&& can be used to execute a command if the previous command on the same line was succesful.
|| Can be used to execute a command if the previous command failed / did not execute.
Coloring text output
Findstr can be used to read a filename and display it using hex color values. This can be used for printing strings by creating filenames with text matching the string you wish to output, provided the characters in the string aren't invalid for use in filenames.
Here's an example that uses these two main points to effect the desired output:
#Echo off
rem /* Macro Definitions */
For /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (set "DEL=%%a")
rem /* %\C% - Color macro; No error checking. Usage:
::: %\C:?=HEXVALUE%Output String
::: Concatenated: (%\C:?=HEXVALUE%Output String) & (%\C:?=HEXVALUE%Output String)
::: Concatenated during conditional execution: ((%\C:?=HEXVALUE%Output String) & (%\C:?=HEXVALUE%Output String))
rem To force a new line; terminate an output string with \n */
Set "\C=For %%o in (1 2)Do if %%o==2 (( <nul set /p ".=%DEL%" > "^^!os:\n=^^!" ) & ( findstr /v /a:? /R "^$" "^^!os:\n=^^!" nul ) & ( del "^^!os:\n=^^!" > nul 2>&1 ) & (If not "^^!os:\n=^^!" == "^^!os^^!" (Echo/)))Else Set os="
rem /* Ensure macro escaping is correct depending on delayedexpansion environment type */
If Not "!![" == "[" (
Set "\C=%\C:^^=^%"
)
::: SCRIPT MAIN BODY
Setlocal EnableExtensions EnableDelayedExpansion
PUSHD "%~dp0"
ping -n 1 www.google.com | find "TTL" > nul && ((%\C:?=20%www.google.com)&(%\C:?=02% online\n)) || ((%\C:?=40%www.google.com)&(%\C:?=04% offline\n))
ping -n 1 www.googlefalse.com | find "TTL" > nul && ((%\C:?=20%www.googlefalse.com)&(%\C:?=02% online\n)) || ((%\C:?=40%www.googlefalse.com)&(%\C:?=04% offline\n))
POPD
Endlocal
Goto :Eof

How can I make text engine in cmd

I try to make text engine in cmd.
So I use this code:
#echo off
cls
echo h
cls
echo he
cls
echo hel
cls
echo hell
cls
echo hello
But when I run the file I can't see any text.
So I used another code:
#echo off
cls
echo h
goto :2
:2
cls
echo he
goto :3
:3
cls
echo hel
goto :4
:4
cls
echo hell
goto :5
:5
cls
echo hello
When I first open the file I only see the he. After that I see no text.
What did I did wrong?
I want to know why it has error and how to fix it to make text engine.
Here's an example of a windowsbatch-file which doesn't do what your example is demonstrating, but does something I think you may prefer instead:
#Set "TextString=This is my text string!"
#For /F %%G In ('"Prompt $H&For %%H In (1) Do Rem"') Do #Set "BS=%%G"
#(For /F Delims^=^ EOL^= %%G In ('(%SystemRoot%\System32\cmd.exe /D /S ^
/U /V /C "Echo=!TextString!"^) ^| %SystemRoot%\System32\find.exe /V ""'
) Do #Set /P "=.%BS%%%G" 0< NUL & %SystemRoot%\System32\PATHPING.EXE ^
127.0.0.1 -n -q 1 -p 150 1> NUL) & Echo=
#Pause
You simply place your required text to be printed, into the first line (between the = and closing "), and double-click it to run and view. If the intent is to run the script directly from cmd, you do not need the last line, #Pause, and can safely remove it.
As a result of a comment, I have decided to present the code in a slightly different way, so that it can be reused for different strings.
#Echo Off
SetLocal EnableExtensions DisableDelayedExpansion
For /F %%G In ('"Prompt $H&For %%H In (1) Do Rem"') Do Set "BS=%%G"
Set "TextString=This is my text string!"
Call :GhostTypeIt
Set "TextString=This is "another" string."
Call :GhostTypeIt
Set "TextString=This & That are <words>."
Call :GhostTypeIt
Pause
Exit /B
:GhostTypeIt
(For /F Delims^=^ EOL^= %%G In ('(%SystemRoot%\System32\cmd.exe /D /S ^
/U /V /C "Echo=!TextString!"^) ^| %SystemRoot%\System32\find.exe /V ""'
) Do Set /P "=.%BS%%%G" 0< NUL & %SystemRoot%\System32\PATHPING.EXE ^
127.0.0.1 -n -q 1 -p 150 1> NUL) & Echo=
GoTo :EOF

Batch file to determine websites in IE

Is there a piece of code which can be used in a batch file to determine if firstly IE is open, and if so which websites are open in the tab(s)?
I am needing to force close IE when a user locks their PC, and if a specific website is open.
Thanks in advance.
Give a try for this batch file :
#echo off
Title Checking Running Process and Get their command lines
setlocal enabledelayedexpansion
Mode 90,25 & color 0A
Set "ProcessName=iexplore.exe"
Set "String2Search=facebook"
Call :CheckRunning !ProcessName!
If /I "%flag%"=="True" (
color 0A
echo %flag%
Call :GetCommandLine !ProcessName!
echo(
Call :CheckString_in_URL "%String2Search%"
) else (
color 0C
echo %flag%
echo !ProcessName! is not running !
pause>nul & exit
)
Exit
::********************************************************************************************************
:CheckRunning <ProcessName>
Set "ProcessName=%1"
tasklist /NH /FI "imagename eq %ProcessName%" 2>nul |find /i "%ProcessName%" >nul
If not errorlevel 1 ( Set "flag=True" ) else ( Set "flag=False" )
Exit /b
::********************************************************************************************************
:GetCommandLine <ProcessName>
Set "ProcessCmd="
for /f "tokens=2 delims==" %%P in ('wmic process where caption^="%~1" get commandline /format:value ^| findstr /I "%~1" ^| find /I /V "%~nx0" 2^>nul') do (
Set "ProcessCmd=%%P"
echo !ProcessCmd!
)
Exit /b
::******************************************************************************************************
:Kill <ProcessName>
Taskkill /IM "%~1" /F>nul 2>&1
Exit /b
::******************************************************************************************************
:CheckString_in_URL <String2Search>
set "String2Search=%~1"
(
echo Set objFso = CreateObject^("Scripting.FileSystemObject"^)
echo Set colShWindows = CreateObject^("shell.application"^).Windows
echo For Each w In colShWindows
echo If objFso.GetFileName^(LCase^(w.FullName^)^) = "iexplore.exe" Then
echo WScript.Echo w.LocationURL
echo End If
echo Next
)>"%Temp%\iexplore_tabs.vbs"
setlocal EnableDelayedExpansion
for /f %%a in ('cscript //nologo "%Temp%\iexplore_tabs.vbs"') do (
set /a index+=1
set "URL[!index!]=%%a"
)
for /L %%i in (1,1,%index%) do (
echo !URL[%%i]! | find /I "%String2Search%">nul && (
echo Found this string "%String2Search%" in the URL "!URL[%%i]!"
echo(
echo Did you want to kill this process "!ProcessName!" Y/N ?
Set /p "Answer="
If /I "!Answer!"=="Y" ( Call :Kill "!ProcessName!" ) else ( exit )
) || (
echo No string like "%String2Search%" found in "!URL[%%i]!"
Timeout /T 5 /nobreak>nul
)
)
exit /b
::******************************************************************************************************
I'm grateful to aGerman that give me the idea of how to enumerate the URLs of the InternetExplorer tabs

How to create a checklist with a bat file/batch script in the console window?

I'm looking to create a checklist in a console window to help users choose certain options they would like to install. This kind of output:
Please select options to install:
[x]Option 1
[ ]Option 2
>[x]Option 3
[x]Option 4
Where the user can move the cursor throughout the list and select the options.
I have a very, very vague idea of how I might do this code, testing with just two options. But if there is anyone who already has a solidified idea of how this would work and could share I would be very appreciative!
Test code for those who want to see it:
#echo off
call:main
end /b 0
:main
set /p choice= "Would you like to enable option one? (yes/no): "echo(
if %choice%==yes (
set option1=1
)
if %choice%==no (
set option1=0
)
call:mod1
set /p choice= "Would you like to enable option two? (yes/no): "echo(
if %choice%==yes (
set option2=1
)
if %choice%==no (
set option2=0
)
call:mod2
:mod1
if %option1%==1 (
echo [x] Option 1
)
if %option1%==0 (
echo [ ] Option 1
)
:mod2
if %option2%==1 (
echo [x] Option 1
)
if %option2%==0 (
echo [ ] Option 1
)
You could try this:
#echo off
setlocal EnableDelayedExpansion
for /f %%A in ('"prompt $H &echo on &for %%B in (1) do rem"') do set BS=%%A
set "getKeyMacro=powershell -noprofile "^
while (-not (37..40+13).contains($x)) {^
$x = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown').VirtualKeyCode^
}^
if ($x -eq 13) {^
'enter'^
}^
('left','up','right','down')[$x - 37]^
""
set "option1=0"
set "option2=0"
set "option3=0"
set "option4=0"
set "selected=1"
:select
cls
echo use ^<right^> arrow to continue, ^<up^> and ^<down^> to select, and ^<enter^> to toggle
FOR /L %%G IN (1,1,4) DO (
set "display=[ ]"
if !option%%G! equ 1 set "display=[x]"
if %%G equ !selected! set "display=^>!display!
echo !display! Option %%G
)
FOR /F "delims==" %%G IN ('%getKeyMacro%') DO set "key=%%G"
if "%key%"=="up" set /a "selected-=1"
if "%key%"=="down" set /a "selected+=1"
if %selected% lss 1 set "selected=1"
if %selected% gtr 4 set "selected=4"
if "%key%"=="enter" goto toggle
if "%key%"=="right" goto OK
goto select
:toggle
set /a "option%selected%+=1"
set /a "option%selected%=!option%selected%!%%2"
goto select
:OK
FOR /L %%G IN (1,1,4) DO (
if !option%%G! equ 1 (
echo %%G selected
)
)
pause
Note that this is very heavily dependent on Delayed Expansion, so you might want to read up on it here.
Second note: this needs powershell so you can use up and down arrow keys to select options, enter to toggle currently selected option, and right arrow to continue.
EDIT
Updated version, this allows you to set the display names for the options, but you need to specify the amount of options aswell:
#echo off
setlocal EnableDelayedExpansion
for /f %%A in ('"prompt $H &echo on &for %%B in (1) do rem"') do set BS=%%A
set "getKeyMacro=powershell -noprofile "^
while (-not (37..40+13).contains($x)) {^
$x = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown').VirtualKeyCode^
}^
if ($x -eq 13) {^
'enter'^
}^
('left','up','right','down')[$x - 37]^
""
set "option1=0"
set "option2=0"
set "option3=0"
set "option4=0"
set "option1name=Install thing 1"
set "option2name=Do thing 2"
set "option3name=Execute thing 3"
set "option4name=Run thing 4"
set "maxOptions=4"
set "selected=1"
:select
cls
echo use ^<right^> arrow to continue, ^<up^> and ^<down^> to select, and ^<enter^> to toggle
FOR /L %%G IN (1,1,%maxOptions%) DO (
set "display=[ ]"
if !option%%G! equ 1 set "display=[x]"
if %%G equ !selected! set "display=^>!display!
echo !display! !option%%Gname!
)
FOR /F "delims==" %%G IN ('%getKeyMacro%') DO set "key=%%G"
if "%key%"=="up" set /a "selected-=1"
if "%key%"=="down" set /a "selected+=1"
if %selected% lss 1 set "selected=1"
if %selected% gtr %maxOptions% set "selected=!%maxOptions%!"
if "%key%"=="enter" goto toggle
if "%key%"=="right" goto OK
goto select
:toggle
set /a "option%selected%+=1"
set /a "option%selected%=!option%selected%!%%2"
goto select
:OK
FOR /L %%G IN (1,1,%maxOptions%) DO (
if !option%%G! equ 1 (
echo %%G selected
)
)
pause
EDIT #2
Now uses the for loop by #Aacini to initiate the variables so this only needs to happen once, and so there is no need for a manual maxoption any more:
#echo off
setlocal EnableDelayedExpansion
set "getKeyMacro=powershell -noprofile "^
while (-not (37..40+13).contains($x)) {^
$x = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown').VirtualKeyCode^
}^
if ($x -eq 13) {^
'enter'^
}^
('left','up','right','down')[$x - 37]^
""
set "num=0"
for %%a in ("Install thing 1"
"Do thing 2"
"Execute thing 3"
"Run thing 4") do (
set /A num+=1
set "option!num!=0"
set "option!num!name=%%~a"
)
set "maxOptions=%num%"
set "selected=1"
:select
cls
echo use ^<right^> arrow to continue, ^<up^> and ^<down^> to select, and ^<enter^> to toggle
FOR /L %%G IN (1,1,%maxOptions%) DO (
set "display=[ ]"
if !option%%G! equ 1 set "display=[x]"
if %%G equ !selected! set "display=^>!display!
echo !display! !option%%Gname!
)
FOR /F "delims==" %%G IN ('%getKeyMacro%') DO set "key=%%G"
if "%key%"=="up" set /a "selected-=1"
if "%key%"=="down" set /a "selected+=1"
if %selected% lss 1 set "selected=1"
if %selected% gtr %maxOptions% set "selected=!%maxOptions%!"
if "%key%"=="enter" goto toggle
if "%key%"=="right" goto OK
goto select
:toggle
set /a "option%selected%+=1"
set /a "option%selected%=!option%selected%!%%2"
goto select
:OK
FOR /L %%G IN (1,1,%maxOptions%) DO (
if !option%%G! equ 1 (
echo %%G selected
)
)
pause
#echo off
setlocal EnableDelayedExpansion
rem Define the text for the options
set "num=0"
for %%a in ("First option"
"Second option"
"Third option"
"Fourth option") do (
set /A num+=1
set "msg[!num!]=%%~a"
set "opt[!num!]= "
)
set "digits=0123456789"
:select
(cls
echo Press digit to mark/unmark options, or X to end
echo/
for /L %%i in (1,1,%num%) do echo !digits:~%%i,1!. [!opt[%%i]!] !msg[%%i]!
)
choice /C !digits:~1,%num%!X /N > NUL
if %errorlevel% gtr %num% goto endSelect
set "sel=%errorlevel%"
if "!opt[%sel%]!" equ "X" (set "opt[%sel%]= ") else set "opt[%sel%]=X"
goto select
:endSelect
echo/
echo/
for /L %%i in (1,1,%num%) do (
if "!opt[%%i]!" equ "X" (
echo %%i selected
)
)

Resources