Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Menu to run commands

75 views
Skip to first unread message

Docfxit

unread,
Oct 12, 2016, 2:21:46 AM10/12/16
to
I would like a bat menu to run commands.

I would like a list of descriptions:commands
(It doesn't have to be exactly like the above)

My list looks like this:
ShowInfo:VBoxManage showvminfo %vmname%
Create a Snapshot:VBoxManage snapshot %vmname% take
StartClient:VBoxManage startvm %vmname%
In case you need to revert back to the snapshot:VBoxManage snapshot %vmname% restore
Delete the snapshot because it uses disk space:VBoxManage snapshot %vmname% delete

I would like a menu so the user can choose a numbered item with descriptions.

1. ShowInfo
2. Create a Snapshot
3. StartClient
4. In case you need to revert back to the snapshot
5. Delete the snapshot because it uses disk space

When a number is selected the command associated with it would be run.

At the moment my bat file looks like this:

:: Start of bat file
C:
cd "\Programs\Virtualbox"
set uuid=78e3d240-ab46-48bf-b9ef-67197c09e1b5
set vmname=Win7
ShowInfo:VBoxManage showvminfo %vmname%
Create a Snapshot:VBoxManage snapshot %vmname% take
StartClient:VBoxManage startvm %vmname%
In case you need to revert back to the snapshot:VBoxManage snapshot %vmname% restore
Delete the snapshot because it uses disk space:VBoxManage snapshot %vmname% delete
:: End of bat file

Thank you,
Docfxit

foxidrive

unread,
Oct 12, 2016, 6:13:13 AM10/12/16
to
On 12/10/2016 17:21, Docfxit wrote:
> I would like a bat menu to run commands.


This is an encoded BASE64 script to preserve the long lines of description
by the Author Aacini.

His menu uses an ingenious method to give a very nice input routine in a
GUI format that uses up/down arrow keys to select the menu options.

I've re-phrased a few of your menu choices to reduce the line length.
Have a look see anyway. This batch script merely creates the menu batch
script.


@echo off
if not exist "Menu with scrolling selection.bat" (
echo creating "Menu with scrolling selection.bat"
(
echo DQoNCkBpZiAoQENvZGVTZWN0aW9uID09IEBCYXRjaCkgQHRoZW4NCg0KDQpAZWNo
echo byBvZmYNCnNldGxvY2FsIEVuYWJsZURlbGF5ZWRFeHBhbnNpb24NCg0KcmVtIE11
echo bHRpLWxpbm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1AgInZhcj1TZWxlY3QgdGhlIGRlc2lyZWQgb3B0aW9uOiAiDQplY2hv
echo Lw0KaWYgIiV2YXIlIiBlcXUgImV4aXQiIGdvdG8gOkVPRg0KZWNobyBPcHRpb24g
echo c2VsZWN0ZWQ6ICIldmFyJSINCnBhdXNlDQpnb3RvIG5leHRPcHQNCg0KDQpAZW5k
echo DQoNCnZhciB3c2hTaGVsbCA9IFdTY3JpcHQuQ3JlYXRlT2JqZWN0KCJXU2NyaXB0
echo LlNoZWxsIiksDQogICAgZW52VmFyID0gd3NoU2hlbGwuRW52aXJvbm1lbnQoIlBy
echo b2Nlc3MiKSwNCiAgICBudW1PcHRzID0gcGFyc2VJbnQoZW52VmFyKCJudW1PcHRz
echo IikpOw0KDQppZiAoIFdTY3JpcHQuQXJndW1lbnRzLkxlbmd0aCApIHsNCiAgIC8v
echo IEVudGVyIG1lbnUgb3B0aW9ucw0KICAgZm9yICggdmFyIGk9MTsgaSA8PSBudW1P
echo cHRzOyBpKysgKSB7DQogICAgICB3c2hTaGVsbC5TZW5kS2V5cyhlbnZWYXIoIm9w
echo dGlvblsiK2krIl0iKSsie0VOVEVSfSIpOw0KICAgfQ0KfSBlbHNlIHsNCiAgIC8v
echo IEVudGVyIGEgRjcgdG8gb3BlbiB0aGUgbWVudQ0KICAgd3NoU2hlbGwuU2VuZEtl
echo eXMoIntGN30iKTsNCn0NCg==
)>"decode.tmp"
certutil /decode /f "decode.tmp" "Menu with scrolling selection.bat" >nul
del "decode.tmp"
)

Docfxit

unread,
Oct 12, 2016, 12:56:09 PM10/12/16
to
This is a really nice menu. I'm impressed. :-)

Where do I put the commands to run when a menu item is selected?

Thank you,

Docfxit

pro...@berkeley.edu

unread,
Oct 12, 2016, 8:46:39 PM10/12/16
to
On Wednesday, October 12, 2016 at 3:13:13 AM UTC-7, foxidrive wrote:
> On 12/10/2016 17:21, Docfxit wrote:
> > I would like a bat menu to run commands.
>
>
> This is an encoded BASE64 script to preserve the long lines of description
> by the Author Aacini.
>
> His menu uses an ingenious method to give a very nice input routine in a
> GUI format that uses up/down arrow keys to select the menu options.
>
> I've re-phrased a few of your menu choices to reduce the line length.
> Have a look see anyway. This batch script merely creates the menu batch
> script.
>

I can imagine how it might work, but it won't work for me (Win 7 Pro 64).
I only see the line in all caps and then the line that says enter your
choice, but the choices don't show up.

Simpler is better.

>\cmd\demo\menu3247
1 - - - ShowInfo
2 - - - Create a Snapshot
3 - - - StartClient
4 - - - To revert back to the snapshot
5 - - - Delete an overly large snapshot
Your choice? 5
You selected Delete an overly large snapshot.

>listfile \cmd\demo\menu3247.cmd
==========begin \cmd\demo\menu3247.cmd ==========
0001. @echo off
0002. set/a n=1
0003. for %%e in (
0004. "ShowInfo"
0005. "Create a Snapshot"
0006. "StartClient"
0007. "To revert back to the snapshot"
0008. "Delete an overly large snapshot"
0009. ) do call :CHOICE %%e
0010. :ASK
0011. set "pick="
0012. set /p pick="Your choice? "
0013. if not defined pick goto :EOF
0014. if not defined choice.%pick% (
0015. echo/Invalid choice.
0016. goto :ASK
0017. )
0018. echo/You selected !choice.%pick%!.
0019. goto :EOF
0020. :CHOICE
0021. set choice.%n%=%~1
0022. echo/%n% - - - %~1
0023. set/a n+=1
0024. goto :EOF
==========end \cmd\demo\menu3247.cmd ==========

Phil Robyn

foxidrive

unread,
Oct 13, 2016, 12:10:23 AM10/13/16
to
On 13/10/2016 11:46, pro...@berkeley.edu wrote:
>>
>> This is an encoded BASE64 script to preserve the long lines of description
>> by the Author Aacini.
>>
>> His menu uses an ingenious method to give a very nice input routine in a
>> GUI format that uses up/down arrow keys to select the menu options.
>
> I can imagine how it might work, but it won't work for me (Win 7 Pro 64).
> I only see the line in all caps and then the line that says enter your
> choice, but the choices don't show up.

Hi Phil,

Could it be that DOSKEY.EXE or is missing from your path for some reason?
Or CSCRIPT.EXE is disabled?


Docfxit Wrote

> This is a really nice menu. I'm impressed.
> Where do I put the commands to run when a menu item is selected?

There are various ways to implement your choices and I can't advise you on
that as your task isn't clear.

You add your code before the "@end" line and below the "goto nextOpt"
command. The code below in paragraphs 1 and 3 is inside the existing script.


You can list a single command after the "if" compares below and I think
you'll be able to work out what you need to do from that - but I've shown a
method using subroutines below.


===================================


if "%var%" equ "exit" goto :EOF
echo Option selected: "%var%"

if "%var%" equ "ShowInfo" your command here or call :routine1
if "%var%" equ "Create a Snapshot" as above
if "%var%" equ "StartClient" as above
if "%var%" equ "To revert back to the snapshot" as above
if "%var%" equ "Delete an overly large snapshot" as above

pause
goto nextOpt

:routine1
blah blah
goto :EOF

:routine2
blah blah
goto :EOF

:routine3
blah blah
goto :EOF

:routine4
blah blah
goto :EOF

:routine5
blah blah
goto :EOF

@end


pro...@berkeley.edu

unread,
Oct 13, 2016, 3:11:25 AM10/13/16
to
On Wednesday, October 12, 2016 at 9:10:23 PM UTC-7, foxidrive wrote:
> On 13/10/2016 11:46, pro...@berkeley.edu wrote:
> >>
> >> This is an encoded BASE64 script to preserve the long lines of description
> >> by the Author Aacini.
> >>
> >> His menu uses an ingenious method to give a very nice input routine in a
> >> GUI format that uses up/down arrow keys to select the menu options.
> >
> > I can imagine how it might work, but it won't work for me (Win 7 Pro 64).
> > I only see the line in all caps and then the line that says enter your
> > choice, but the choices don't show up.
>
> Hi Phil,
>
> Could it be that DOSKEY.EXE or is missing from your path for some reason?
> Or CSCRIPT.EXE is disabled?
>
>

I will start over tomorrow. Maybe I made a typo or something.

I do the same thing with Wylbur to change the font for vDOS. Build the
executable on the fly, based on the list of .ttf fonts installed, then
put the list on the screen, line with the current font highlighted in
a different color, up- or down-arrow to select (the highlighting moves
up or down), then F3 to change the font to whatever is highlighted.
I would even post the code but the lines are too long and a few of them
would wrap.

Docfxit

unread,
Oct 13, 2016, 12:18:49 PM10/13/16
to
It's working really great. Very nice menu.

There is only one thing I don't understand.
This equation:
if "%var%" equ "ShowInfo " call :routine1
won't test as true unless there is a space after ShowInfo
There is no space when the menu gets created:
for %%a in (

"ShowInfo"
"Create a Snapshot"
"StartClient"
"To revert back to the snapshot"
"Delete an overly large snapshot"

) do (
set /A numOpts+=1
set "option[!numOpts!]=%%~a "
)
set /A numOpts+=1
set "option[!numOpts!]=exit"

Thank you very much,
Docfxit

foxidrive

unread,
Oct 13, 2016, 8:22:12 PM10/13/16
to
On 14/10/2016 03:18, Docfxit wrote:
> It's working really great. Very nice menu.
>
> There is only one thing I don't understand.
> This equation:
> if "%var%" equ "ShowInfo " call :routine1
> won't test as true unless there is a space after ShowInfo
> There is no space when the menu gets created:

> set "option[!numOpts!]=%%~a "

It's useful that you posted that line, coz the space is after the %%a and I
introduced it by accident when editing.

Take it out and it should solve that.

Nate S

unread,
Oct 14, 2016, 5:24:44 AM10/14/16
to
This is a cool batch file.

How could I make the default option on first run 0 instead of exit?

pro...@berkeley.edu

unread,
Oct 14, 2016, 3:17:12 PM10/14/16
to
On Wednesday, October 12, 2016 at 9:10:23 PM UTC-7, foxidrive wrote:
> On 13/10/2016 11:46, pro...@berkeley.edu wrote:
> >>
> >> This is an encoded BASE64 script to preserve the long lines of description
> >> by the Author Aacini.
> >>
> >> His menu uses an ingenious method to give a very nice input routine in a
> >> GUI format that uses up/down arrow keys to select the menu options.
> >
> > I can imagine how it might work, but it won't work for me (Win 7 Pro 64).
> > I only see the line in all caps and then the line that says enter your
> > choice, but the choices don't show up.
>
> Hi Phil,
>
> Could it be that DOSKEY.EXE or is missing from your path for some reason?
> Or CSCRIPT.EXE is disabled?
>
>

OK, I started over from the beginning. I repasted my original copy of your
file to create 'Menu with scrolling selection.bat' and saved it as file
xMakeBat.cmd in a directory named \Sandbox. I executed xMakeBat and the
file 'Menu with scrolling selection.bat' was created.

DOSKEY.EXE is in the path.
CSCRIPT.EXE is in the path. (I assume it is not disabled. How does one
disable it?)

When I run 'Menu ... .bat', all I see are these lines:

MULTI-LINE MENU WITH OPTIONS SELECTION


Select the desired option:

If I enter something, then it says,

Option selected: "(whatever I entered)"

and the only way out is CTRL-C. But at no time are any options ever
displayed.

Chalk it up to some obscure difference between Win7Pro64 and later versions?

--
Phil R.

foxidrive

unread,
Oct 15, 2016, 4:15:50 AM10/15/16
to
On 15/10/2016 06:17, pro...@berkeley.edu wrote:
> On Wednesday, October 12, 2016 at 9:10:23 PM UTC-7, foxidrive wrote:
>> On 13/10/2016 11:46, pro...@berkeley.edu wrote:
>>>>
>>>> This is an encoded BASE64 script to preserve the long lines of description
>>>> by the Author Aacini.
>>
>> Hi Phil,
>>
>> Could it be that DOSKEY.EXE or is missing from your path for some reason?
>> Or CSCRIPT.EXE is disabled?
>>
>>
>
> OK, I started over from the beginning. I repasted my original copy of your
> file to create 'Menu with scrolling selection.bat' and saved it as file
> xMakeBat.cmd in a directory named \Sandbox. I executed xMakeBat and the
> file 'Menu with scrolling selection.bat' was created.
>
> DOSKEY.EXE is in the path.
> CSCRIPT.EXE is in the path. (I assume it is not disabled. How does one
> disable it?)
>
> When I run 'Menu ... .bat', all I see are these lines:
>
> MULTI-LINE MENU WITH OPTIONS SELECTION
>
>
> Select the desired option:
>
> If I enter something, then it says,
>
> Option selected: "(whatever I entered)"
>

What you should see is a white 'popup' sort of box with purple menu choices
over the cmd window and a highlighted bar that goes up and down using the
arrow keys.

You've done the right things but open a cmd prompt and type

cscript /?
doskey /?

It's not likely to be a compatibility issue.



Kerr Mudd-John

unread,
Oct 15, 2016, 10:12:47 AM10/15/16
to
On Sat, 15 Oct 2016 09:15:47 +0100, foxidrive <foxi...@server.invalid>
wrote:
I get the same (lack of popup) W XP3. cscript 5.7 doskey (came with XP)

Hmmm worked on closing the cmd prompt & rerunning!


--
Bah, and indeed, Humbug

foxidrive

unread,
Oct 15, 2016, 11:21:37 AM10/15/16
to
On 16/10/2016 01:12, Kerr Mudd-John wrote:

>> You've done the right things but open a cmd prompt and type
>>
>> cscript /?
>> doskey /?
>>
>> It's not likely to be a compatibility issue.
>
> I get the same (lack of popup) W XP3. cscript 5.7 doskey (came with XP)
>
> Hmmm worked on closing the cmd prompt & rerunning!

Does it do the same thing if you reboot and try the script again??



foxidrive

unread,
Oct 15, 2016, 11:25:44 AM10/15/16
to
On 14/10/2016 20:24, Nate S wrote:
>>> It's working really great. Very nice menu.
>
> This is a cool batch file.
>
> How could I make the default option on first run 0 instead of exit?

In the menu choices place the "Exit" option as the last one in the list.

They are ordered as they are placed in the batch file.


I'm in the process of improving the layout and documented text in the script.
Aacini is the author of the script and he lives on www.Dostips.com as well
as other batch forums.


pro...@berkeley.edu

unread,
Oct 15, 2016, 3:44:35 PM10/15/16
to
Yes, I understood that I should see what one sees when one presses <F7> in a
console session window; ordinarily, the console command stack would be shown,
but this program replaces the console command stack with the menu options.
I get all that. But that doesn't happen when I run the program on my machine.

cscript /? and doskey /? produce all the expected information.

--
Phil R.

foxidrive

unread,
Oct 15, 2016, 7:12:17 PM10/15/16
to
On 16/10/2016 06:44, pro...@berkeley.edu wrote:
> Yes, I understood that I should see what one sees when one presses <F7> in a
> console session window; ordinarily, the console command stack would be shown,
> but this program replaces the console command stack with the menu options.
> I get all that. But that doesn't happen when I run the program on my machine.
>
> cscript /? and doskey /? produce all the expected information.
>
> --
> Phil R.


You're a clever bloke Phil and I know your name from many many years ago
and your high level of capability in batch scripting.

So how come it doesn't work?

My first guess is that cscript may be locked down in your group policy or
another security restriction. It works here in Win7 just fine.

Are you able to run another cscript batch file to see how that works?


pro...@berkeley.edu

unread,
Oct 15, 2016, 8:09:58 PM10/15/16
to
I think maybe it's because the cscript ENGINE is JSCRIPT in this case. I bet
I did disable that at some point. A long time ago. I'm not on any office
network or subject to any group policy, it's just me and Comcast. I'll look
around for some cscript test files....

--
Phil R.

Kerr Mudd-John

unread,
Oct 16, 2016, 6:13:33 AM10/16/16
to
On Sat, 15 Oct 2016 16:21:35 +0100, foxidrive <foxi...@server.invalid>
wrote:
Sorry, I mostly just Hibernate.

Perhaps it's something nasty I've been running in my cmd box. (e.g. my own
us->uk key swapper)
0 new messages