Help with a program launching batch file

Closed
serithwing - Oct 26, 2008 at 09:22 PM
 Little Helper - May 15, 2009 at 05:11 AM
Hello,
I have been working on a batch file that will run any shortcut i want. i have a keyboard that has some programable keys i have one folder with all the shortcuts to my programs i am looking for a batch file that i can run and then run any shortcut in that folder. so far my best attepmt is very crude.

@Echo Game 1 Age of Empires III
@Echo Game 2 Dungeon Siege
@Echo Game 3 Dungeon Siege Legends of Aranna
@Echo Game 4 Etherlords II
...
set /p Game=Play?

i have to edit my batch program every time i add or remove shortcuts. pokeing aroudn the net i came up with this bit of code that seems to help but i can not figure out how to use it after it maeks the variables

@echo off
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in ('dir *.lnk /b') do (
set /a n+=1
set v!n!=%%a
)
set v

the bigest problem now seems to be how to get it to list off in numeratical order and how to call the right shortcut. what i am really looking for is a menu that i can then run the corisponding file and all i need ot do to add or subtract items is remove or add the shortcut to the folder the batch file is in. Thank you in advance for the help

6 replies

the problem is i have to edit the batch file each time i change the contentes of the folder. i am looking for a way to make a batch file that can just be droped into any folder of links and work with out editing it. the batch file needs to do several tasks 1st it needs to make a menu with poplulated with all the links in the folder. 2nd it needs to be able to launch those programs after the user picks what one to run. i am haveing problems accessing the variables that this bit of code produces

@echo off
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in ('dir *.lnk /b') do (
set /a n+=1
set v!n!=%%a
)
set v

i can access the values by %v1% but i am unable to figure out how to access the values with an adtional variable.
i have tried %vc% as well as %v!c!% and many other combanations i figure i can set c to the program number that corasponds to the link i want run. The other problem i have with the above code is it does not list in order it seems to list out v1 v10 v11 v12 v13 v14 v2 ....
3
Little Helper
May 15, 2009 at 05:11 AM
...i have tried %vc% as well as %v!c!%....
I think you just missed the working configuration, !v%c%! should work, as %c% always gets expanded BEFORE the line is executed, and then !v1! will be executed (assuming c=1).

Regarding listing in order, this should allow you to do a FOR /L to run through the list.
But it would probably be easier to just use an ECHO inside the FOR /F loop you already have to find the programs :-)

I think this does what you want:

@echo off 
setLocal EnableDelayedExpansion 

for /f "tokens=* delims= " %%a in ('dir *.lnk /b') do ( 
set /a n+=1 
set v!n!=%%a 
echo !n!: %%a
) 

set /P c=Please choose a number: 

start !v%c%!
0
I guess you should be able to map your programmable keys directly to games' exe. That should serve the purpose.
2
yeah to do that right click on the game and do make a shortcut withc is way simpler than making a batch file. But if you want a batch file this is what you have to type for example

@echo off
echo Age of Empires 3
echo starting
start C:\ProgramFiles\microsoftgames\ageofempires3\age3.exe
echo started
0
i realy trying to get a batch file to make a working menu of all the shortcuts in one folder the current one i have to manully edit it everytime i add or subtract a shortcut to the folder
0
Putting %CD%\ before the path to your programs, and you could use a lot of IF NOT EXIST commands to try and create a makeshift menu..

i'd give an example, but i'm working on my own batch problem..

I've got a setup that needs to execute from a directory in a CD, but it can't be run from DOS, so i need a batch file to start a link to that setup, but the batch treats it as the Setup.exe, not the link, and tries to run it in DOS again..
0

Didn't find the answer you are looking for?

Ask a question
This is the easiest way using a input choice


@echo off
:start
cls
@Echo Game 1 Age of Empires III
@Echo Game 2 Dungeon Siege
@Echo Game 3 Dungeon Siege Legends of Aranna
@Echo Game 4 Etherlords II
set /p userinp=choose a number(1-6):
set userinp=%userinp:~0,1%
if "%userinp%"=="1" goto 1
if "%userinp%"=="2" goto 2
if "%userinp%"=="3" goto 3
if "%userinp%"=="4" goto 4
echo invalid choice
goto start
:1
(start Age of Empires III )
goto end
:2
(start Dungeon Siege )
goto end
:3
(start Dungeon Siege Legends of Aranna)
goto end
:4
(start Etherlords II)
goto end
:end
0
This is what worked for me. It lists all the shortcut files in the folder. You choose an option and the game runs.
The .bat file must however be in the same folder as all of your shortcuts for it to work as it is.

@echo off
:menu
cls
echo.
echo. GAME SETUP AND SELECTION MENU
echo.
echo. ( Q quits )
echo.
cd /d %~dp0
setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%a in ('dir *.lnk *.*.lnk /b') do (
set /a n+=1
set game !n!=%%a
)
set game
echo.
set /p Choice= Please select a game:
echo.
IF /I '%Choice%'=='1' GOTO :1
IF /I '%Choice%'=='2' GOTO :2
IF /I '%Choice%'=='3' GOTO :3
IF /I '%Choice%'=='4' GOTO :4
IF /I '%Choice%'=='5' GOTO :5
IF /I '%Choice%'=='q' GOTO :end
echo.
echo. Computer says no
echo.
pause
goto :menu
:1
call %game 1%
goto :menu
:2
call %game 2%
goto :end
:3
call %game 3%
goto :menu
:4
call %game 4%
goto :menu
:5
call %game 5%
goto :menu
:end
0
yeah thats what i had originaly i was just hopeing there was a way to code teh bat file to make its own menu based onthe contents of the folder i place it in so i could install and uninstall games with out haveing to recode teh batch file but thaks anyways for the help
0
ynrob > serithwing
Feb 8, 2009 at 09:14 AM
Just add more options to your menu ie.
add 100 of these:....

IF /I '%Choice%'=='x' GOTO :x

and 100 of these:....

:x
call %game x%
goto :menu

changing x in each one.... 12,3,4 and so on
then your menu will have 100 possible entries but it will still only list the shortcut files in the folder and if you were to copy more *.lnk files in there they would automatically show up. unless I have misunderstood your question. you should not need to edit the file to ad more items to the menu or to take them off.
0
Ok that one is kinda #^& how about this one. Copy and paste as is int a .bat and run from your .lnk folder




@echo off
:menu
cls
echo. GAME SETUP AND SELECTION MENU
echo. ( Q quits )
echo.__________________________________________________
cd /d %~dp0
setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%a in ('dir *.lnk *.*.lnk /b') do (
set /a n+=1
set game !n!=%%a
)
set game
echo.
set /p Choice= Please select a game:
echo.
IF /I '%Choice%'=='1' call %game 1%
IF /I '%Choice%'=='2' call %game 2%
IF /I '%Choice%'=='3' call %game 3%
IF /I '%Choice%'=='4' call %game 4%
IF /I '%Choice%'=='5' call %game 5%
IF /I '%Choice%'=='1' call %game 6%
IF /I '%Choice%'=='1' call %game 7%
IF /I '%Choice%'=='1' call %game 8%
IF /I '%Choice%'=='1' call %game 9%
IF /I '%Choice%'=='1' call %game 10%
IF /I '%Choice%'=='1' call %game 11%
IF /I '%Choice%'=='1' call %game 12%
IF /I '%Choice%'=='1' call %game 13%
IF /I '%Choice%'=='1' call %game 14%
IF /I '%Choice%'=='1' call %game 15%
IF /I '%Choice%'=='1' call %game 16%
IF /I '%Choice%'=='1' call %game 17%
IF /I '%Choice%'=='1' call %game 18%
IF /I '%Choice%'=='1' call %game 19%
IF /I '%Choice%'=='1' call %game 20%
IF /I '%Choice%'=='1' call %game 22%
IF /I '%Choice%'=='1' call %game 23%
IF /I '%Choice%'=='1' call %game 24%
IF /I '%Choice%'=='1' call %game 25%
IF /I '%Choice%'=='1' call %game 26%
IF /I '%Choice%'=='1' call %game 27%
IF /I '%Choice%'=='1' call %game 28%
IF /I '%Choice%'=='1' call %game 29%
IF /I '%Choice%'=='1' call %game 30%
IF /I '%Choice%'=='q' GOTO :eof
echo.
echo. Computer says no
echo.
pause
goto :menu
0
serithwing > ynrob
Feb 8, 2009 at 05:48 PM
Thank you that works
0