shorterxp Posted August 5, 2018 Posted August 5, 2018 (edited) 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 August 5, 2018 by shorterxp
jaclaz Posted August 5, 2018 Posted August 5, 2018 (edited) 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 August 5, 2018 by jaclaz
shorterxp Posted August 5, 2018 Author Posted August 5, 2018 (edited) 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 August 5, 2018 by shorterxp
jaclaz Posted August 6, 2018 Posted August 6, 2018 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. jaclaz
gunsmokingman Posted August 6, 2018 Posted August 6, 2018 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
shorterxp Posted August 6, 2018 Author Posted August 6, 2018 (edited) 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. Edited August 6, 2018 by shorterxp
aviv00 Posted August 7, 2018 Posted August 7, 2018 use echo like this echo ramdisk| convert f: /fs:ntfs /x
jaclaz Posted August 7, 2018 Posted August 7, 2018 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. Well that uses CHOICE. I wonder if we are communicating jaclaz
shorterxp Posted August 10, 2018 Author Posted August 10, 2018 echo ramdisk| convert f: /fs:ntfs /x That formats hard drive?
jaclaz Posted August 11, 2018 Posted August 11, 2018 14 hours ago, shorterxp said: echo ramdisk| convert f: /fs:ntfs /x That formats hard drive? No. At the most (not as posted) it will convert a volume (F: in this case) to NTFS. https://ss64.com/nt/convert.html jaclaz
shorterxp Posted August 11, 2018 Author Posted August 11, 2018 (edited) 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 August 11, 2018 by shorterxp
jaclaz Posted August 11, 2018 Posted August 11, 2018 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
Yzöwl Posted August 16, 2018 Posted August 16, 2018 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
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now