#1 28 Dec 2018 14:00

Rekrul
Member
Registered: 17 Apr 2016
Posts: 13

The Choice command in Windows XP

I suspect this question will probably go unanswered, but I figured I might as well ask...

For some insane reason, Microsoft decided to omit the Choice command from Windows NT/XP. Apparently it was later available in some sort of resource kit, which I don't have.

I did download a Choice command that works on XP, but it uses a slightly different syntax to that of the Choice command in later versions of Windows. I got it from here;

https://sourceforge.net/projects/vbsmc/files/Resources/

The following works in XP, but not in Win7/8/10;

choice /c1234 Please choose [1-4]: /n

The following works in Win7/8/10, but not XP;

choice /c 1234 /m "Please choose [1-4]:" /n

Is there a version of the Choice command available for XP that will accept the same syntax as used by the Win7/8/10 version?

It would be nice if I didn't have to write two different versions of scripts just to make them compatible across Windows versions.

Offline

#2 28 Dec 2018 17:14

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 990
Website

Re: The Choice command in Windows XP

Why not use SET /P instead?

Alternatively detect the OS with the VER command and then run one of the two choice commands.

Offline

#3 31 Jan 2019 13:56

Rekrul
Member
Registered: 17 Apr 2016
Posts: 13

Re: The Choice command in Windows XP

Sorry I haven't been back in a while...

Simon Sheppard wrote:

Why not use SET /P instead?

How is the SET command a substitute for Choice? I want people to be able to select options from a menu with a single keypress.

Simon Sheppard wrote:

Alternatively detect the OS with the VER command and then run one of the two choice commands.

I suppose that's one solution, although not my preferred one. Anytime I trying adding any kind of logic that depends on analyzing strings, I have a hell of time trying to make it work correctly.

It would be much easier if there were a Choice command for XP that accepted the same syntax as the one for later versions of Windows.

I'll never understand Microsoft's logic. They use a bunch of extremely unintuitive mechanics in their scripting language, supposedly to maintain backwards compatibility with previous scripting languages, but then they just omit the Choice command from XP? Yeah, I'm sure that won't break anything... roll

As it is now, I not only have to write two versions of my scripts if I want to give them to anyone (or add lines to decide which syntax to use), I also have to include either a copy of Choice.exe itself or a link telling people where to download it if they want to run the script on XP.

I know what you're thinking; Why would anyone in 2019 be writing scripts that would work on XP? Well, some of my scripts are intended to help launch old games which some people use older systems to play. Or they're for manipulating files for emulators, which some people also use on older systems if they don't need a lot of power. And there's the fact that I just prefer my scripts to be compatible across most any version of Windows. Which it would be if Microsoft hadn't made the insane decision to leave Choice out of XP.

P.S.

Can you PLEASE do something about the forum logging me out seemingly at random. I start writing a message, go to look something up, make some corrections, click the preview button, it tells me that I'm not logged in and discards my post. At the very least it should preserve my text until I log back in so that I don't lose it all. This is the only forum it seems to happen on.

Offline

#4 10 Feb 2019 23:38

NDog
Member
From: New Zealand
Registered: 31 May 2006
Posts: 119
Website

Re: The Choice command in Windows XP

If you want simple -

@echo off
goto menu
:menu
echo.
echo What would you like to do?
echo.
echo.
echo 1 Backup Activation
echo 2 Restore Activation
echo.


:choice
echo Type your selection and press enter
set /P C=[1,2]?
if "%C%"=="2" goto restore
if "%C%"=="1" goto backup
goto choice

:backup
xcopy "c:\windows\system32\wpa.dbl"  /H /Y /V
xcopy "c:\windows\system32\wpa.bak"  /H /Y /V
echo Backup Complete
exit


:restore
xcopy "wpa.dbl" "c:\windows\system32\" /H /Y /V
xcopy "wpa.bak" "c:\windows\system32\" /H /Y /V
echo Restore Complete
shutdown -r

If you want complex -

@echo off&cls
title %~n0
:: dans cool script
goto :start


calc
notepad
mspaint
wordpad
regedit
cleanmgr
dfrgui
dxdiag
mobsync
MRT
msinfo32
OptionalFeatures
resmon
ServerManager
SndVol
SystemPropertiesAdvanced
UserAccountControlSettings



:start

:: read programs in list into memory
for /f "tokens=* usebackq" %%a in (%0) DO (
  REM echo %%a
  call :sub_files "%%a"
  if "%%a" equ ":start" goto :exitloop)

:exitloop

:menu
cls
set _choice=
set _profile=

echo      ---=== CHOSE AN APP TO RUN ===---
echo.
for /f "usebackq tokens=2-3* delims=_=" %%g in (`set _app 2^>nul`) do (echo   %%g - %%h)
echo.
set /p _choice=Choose something (q to quit): 

if "%_choice%" equ "" goto :menu
if "%_choice%" equ "q" goto :end
if "%_choice%" gtr "0" if "%choice%" lss "%_count%" for /f "usebackq tokens=2-3* delims=_=" %%g in (`set _app 2^>nul`) do (if %%g equ %_choice% start "" %%h)
if not defined _profile goto :menu

:end
exit


:sub_files
  REM echo %~1
  if exist "c:\windows\%~1.exe" set /a _count+=1&goto :sub_files_next
  if exist "c:\windows\system32\%~1.exe" set /a _count+=1&goto :sub_files_next
  :sub_files_next
  if exist "c:\windows\%~1.exe" set _app_%_count%=%~1&goto :eof
  if exist "c:\windows\system32\%~1.exe" set _app_%_count%=%~1&goto :eof
  goto :eof

If you are clever enough (unlike me) you will be able to sort the numbers in proper order, maybe using a for /l or something
Regardless you will have to press enter

Last edited by NDog (11 Feb 2019 00:00)


cmd, vbs, ps, bash
autoit, python, swift

Offline

Board footer

Powered by FluxBB