Skip to content
View in the app

A better way to browse. Learn more.

MSFN

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

BAT CMD - Y/N input without pressing enter?

Featured Replies

Is this possible? The only info I found was here, the first script doesn't work and the second makes no sense:

https://forums.windowssecrets.com/showthread.php/113953-Yes-No-Batch-file-(XP-SP2)

I would like to create a CMD that prompts user y / n question with goto in place. But automatically continue as soon as input is detected (contrast to waiting for another ENTER press to finish).

As it stands:

@echo Log off + log in to complete installation!
SET /P _inputname= Log Off now?:
IF "%_inputname%"=="Y" GOTO :Y
GOTO :end
:Y
cmd.exe /c c:\windows\system32\logoff.exe
:end

 

Edited by shorterxp


You need choice or similar (there are many of such replacements), for some strange reasons the good MS guys removed it from NT4, 2K and XP (it is in the Resource kit) but re-added it in Vista.

*like*:

http://www.donationcoder.com/forum/index.php?topic=31344.0

http://www.robvanderwoude.com/choice.php

In the latter there is a link to "workaround" in pure batch, secondchoice:

http://www.robvanderwoude.com/batexamples.php?fc=S#SecondChoice

http://www.robvanderwoude.com/sourcecode.php?src=secondchoice_xp

Or you can use this clever trick making use of XCOPY:

https://www.dostips.com/forum/viewtopic.php?t=5409

jaclaz

 

Edited by jaclaz

  • Author

Forbidden

You don't have permission to access /board/topic/177670-bat-cmd-yn-input-without-pressing-enter/ on this server.

 

ARGGHHHHHHHHHHHHH not this shTYEt again!!!

Edited by shorterxp

19 hours ago, shorterxp said:

Forbidden

You don't have permission to access /board/topic/177670-bat-cmd-yn-input-without-pressing-enter/ on this server.

 

ARGGHHHHHHHHHHHHH not this shTYEt again!!!

Well, it seemingly went through somehow. :unsure:

jaclaz

Why not use VBS to do what you want. This way you do not have

3rd party apps to do what you want.

  
If MsgBox("Would you like to restart the Computer?",4132,_
"Shut Off Computer") = 6 Then
'-> Code Below Here Yes
 MsgBox "User said yes to restart"
Else
'-> Code Below Here No 
 MsgBox "User said no to restart"
End If 

 

  • Author

Hi, thanks. Theres a bug in forum ("forbidden") shows up when try to use 'code snippet' or 'quote' feature, so I've resorted to using screenshot.

The example on robvanderwoude.com did not work.

The example on wikpedia did work. See below.

untitled.png

 

Edited by shorterxp

use echo like this

echo ramdisk| convert f: /fs:ntfs /x

On 8/6/2018 at 7:47 PM, shorterxp said:

Hi, thanks. Theres a bug in forum ("forbidden") shows up when try to use 'code snippet' or 'quote' feature, so I've resorted to using screenshot.

The example on robvanderwoude.com did not work.

The example on wikpedia did work. See below.

untitled.png

 

Well that uses CHOICE.

I wonder if we are communicating :dubbio:

jaclaz

  • Author

echo ramdisk| convert f: /fs:ntfs /x

 

That formats hard drive?

  • Author

I could have googled that myself :dow:

To clarify:

robvanderwoude.com the choice example, using choice.exe did not work as desired.

The example on wikipedia, also ussing choice.exe, did work.

Edited by shorterxp

I understand that. :)

Point I was trying to make - since your nick is shorterxp and you are using seemingly XP - is that choice.exe is NOT available in XP (nor it is on NT 4.0 or 2K) as it has been re-added to the OS starting from Vista.

So, if you want to create a "portable" .cmd making use of choice.exe you need to (you choose):

1) limit its use to Vista and later system 
2) add to the batch a copy of choice.exe or - in case of redistribution, since MS choice.exe is NOT redistributable - add one of the free replacements for it
3) use a "built-in" replacement/trick/workaround

I checked and the robvanderwoude.com does work BUT it does not provide one of your requests (choosing with a single keypress without pressing ENTER).

The other suggested workaround BOTH works and provides the feature you asked for:

https://www.dostips.com/forum/viewtopic.php?t=5409

basically:

for /F "delims=" %%L in ('xcopy /L /w "%~f0" "%~f0" 2^>NUL') do (
if not defined key set "key=%%L"
)

a more complete example:

@ECHO OFF
SET mykey=
:myChoice
SET myChoice=A suffusion of yellow
ECHO Please Choose:
ECHO Press 1 for Option 1
ECHO Press 2 for Option 3
ECHO Press A for Option Z :w00t:
ECHO Press Enter to choose to not choose
for /F "delims=" %%L in ('xcopy /L /w "%~f0" "%~f0" 2^>NUL') do (
if not defined mykey set "mykey=%%L"
)

SET mykey=%mykey:~-1,1%
IF NOT DEFINED mykey (ECHO You pressed [Enter]) ELSE (SET myChoice=%mykey%)
ECHO You chose: %myChoice%

jaclaz

I think you could use a similar method, instead using replace.exe from a for loop:

@Echo Off & SetLocal EnableExtensions DisableDelayedExpansion

:Loop
Set "#="
Set /P "=Please enter Y or N :"<Nul
For /F Skip^=1^ Delims^=^ EOL^= %%$ In ('Replace ? . /U /W') Do If Not Defined # Set "#=%%$"
Echo(
If /I "%#%"=="Y" GoTo Entrey
If /I "%#%"=="N" GoTo Entren
GoTo Loop

:Entrey
Echo You entered Y & Pause
GoTo :EOF

:Entren
Echo You entered N & Pause
GoTo :EOF

 

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.