%SystemRoot%\system32 secrets: Choice

We won’t assess the next three commands – chglogon, chgport and chguser – because they are all replaced by change. Therefore the next candidate in the race is

choice

While not being helpful alone it could be useful in batch scripts. Those can be actually very powerful, still I like PowerShell more because it allows me to do stupid things faster and of more quality. But just in case you want to do some *.bat files with not linear logic depending on a user’s input, you can use it. For example, you can ask something like this:

=))) Moreover, you can set default choice and auto accept it after some time:

I haven’t pressed a key here, but the command substituted “b” after 5 seconds of waiting.

Getting out the user’s choice is not perfectly straightforward. It doesn’t return the result as I’m used to. It put the result into %ERRORLEVEL% variable. It is not a big deal, but… I’d rather use PowerShell for it, really. Nevertheless, if you are still addicted to DOS shell, it is sometimes your “choice” 😉

This was written by Alexander Trofimov. Posted on Thursday, April 14, 2011, at 10:38 am. Filed under CLI Secrets, Tools. Bookmark the permalink. Follow comments here with the RSS feed. Both comments and trackbacks are currently closed.