Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Need some help with batch file coding
New Posts  All Forums:Forum Nav:

Need some help with batch file coding

post #1 of 17
Thread Starter 
Is there I way I can execute the same command as "pause" but with my own string of text?

What I want to do is this:

Press any key to return to the main menu.

Then the user presses any key and it triggers a goto start line.

This is what I am doing right now:
set /p MAINMENU=Press any key to return to the main menu.
if %MAINMENU% = %MAINMENU% goto :start
The problem with the above is that it requires the user to press enter after entering any string of text.
post #2 of 17
You could @echo the text you wanted, but I don't think there is a way to hide the pause text. Maybe have it call up another file then pause, and have the other file do CLS a few times then print the text you want? Kinda messy and ghetto, but it may work.
Big Baby
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Duo E8400 Wolfdale 3.0 Ghz Asrock P45R2000 WiFi 460 GTX 6GB Patriot Viper DDR3 1333 (2x1GB and 2x2GB) 
Hard DriveOptical DriveOSMonitor
Kingston 64GB SSD, 1TB Hitachi and 3 160GB drives ASUS dual layer SATA II DVD burner Windows 7 Pro 64 Bit and a few virtual machines ;) Hanns.G Hi221D 22" LCD Widescreen 
KeyboardPowerCaseMouse
standard junker nothin' fancy. Yet... HIPER 730 W Rosewill Conqueror Logitech Trackball (TrackMan is the model I think) 
Mouse Pad
The Desk! 
  hide details  
Reply
Big Baby
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Duo E8400 Wolfdale 3.0 Ghz Asrock P45R2000 WiFi 460 GTX 6GB Patriot Viper DDR3 1333 (2x1GB and 2x2GB) 
Hard DriveOptical DriveOSMonitor
Kingston 64GB SSD, 1TB Hitachi and 3 160GB drives ASUS dual layer SATA II DVD burner Windows 7 Pro 64 Bit and a few virtual machines ;) Hanns.G Hi221D 22" LCD Widescreen 
KeyboardPowerCaseMouse
standard junker nothin' fancy. Yet... HIPER 730 W Rosewill Conqueror Logitech Trackball (TrackMan is the model I think) 
Mouse Pad
The Desk! 
  hide details  
Reply
post #3 of 17
Thread Starter 
Do you know of a way I can execute the pause command, but in a different way? I know it's possible--I've used a batch file before that presented me with a menu with options 1 - 9, and if you hit 5 on your keyboard it would automatically run the goto option_5 command.

What does @echo do?
post #4 of 17
@echo will just print text on the screen. For example, in a batch file I have
@echo on
@echo Howdy
@echo off
call c:\\windows\\sol.exe

The @echo on will turn "echoing to the screen" on
@echo Howdy will display "Howdy" on the screen
@echo off will (usually) hide the text that would normally be displayed with the next line that calls up the Windows Solitaire game.

EDIT - To use the @echo command again, you would need to have another @echo on command. For example, if in the above file you then want it to say something after loading solitaire, you would have to add
@echo on
@echo something


As far as using a Pause Menu like you describe, my batch file skills are nowhere near that good, so I have no idea. Sorry!
Edited by Razinhail - 8/9/11 at 2:06pm
Big Baby
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Duo E8400 Wolfdale 3.0 Ghz Asrock P45R2000 WiFi 460 GTX 6GB Patriot Viper DDR3 1333 (2x1GB and 2x2GB) 
Hard DriveOptical DriveOSMonitor
Kingston 64GB SSD, 1TB Hitachi and 3 160GB drives ASUS dual layer SATA II DVD burner Windows 7 Pro 64 Bit and a few virtual machines ;) Hanns.G Hi221D 22" LCD Widescreen 
KeyboardPowerCaseMouse
standard junker nothin' fancy. Yet... HIPER 730 W Rosewill Conqueror Logitech Trackball (TrackMan is the model I think) 
Mouse Pad
The Desk! 
  hide details  
Reply
Big Baby
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Duo E8400 Wolfdale 3.0 Ghz Asrock P45R2000 WiFi 460 GTX 6GB Patriot Viper DDR3 1333 (2x1GB and 2x2GB) 
Hard DriveOptical DriveOSMonitor
Kingston 64GB SSD, 1TB Hitachi and 3 160GB drives ASUS dual layer SATA II DVD burner Windows 7 Pro 64 Bit and a few virtual machines ;) Hanns.G Hi221D 22" LCD Widescreen 
KeyboardPowerCaseMouse
standard junker nothin' fancy. Yet... HIPER 730 W Rosewill Conqueror Logitech Trackball (TrackMan is the model I think) 
Mouse Pad
The Desk! 
  hide details  
Reply
post #5 of 17
Here you go. Using null you can suppress the "Press any key to continue . . ." prompt of Pause and use echo to place your own text at that location.

Code:
echo Press any key to return to the main menu.
pause > nul
goto start

Edited by ALUCARDVPR - 8/10/11 at 10:10pm
post #6 of 17
Ok, my above post was a little bit off. You only need the @ before "echo" if it's a "@echo on" or an "@echo off" command. For the rest of the time you use echo, "echo" is all you need, followed by a space, then what you want on the screen. Sorry about that. My batch file skills have rusted more than I thought!

I tested out the method recommended by ALUCARDVPR, and on my Windows 7 machine, it works, but it creates a file called "Null". You can avoid this by adding this

pause > null
del null

You may not have the same result when you run "pause > null".

I feel like an idiot for completely forgetting about the "null" command. +1 to you ALUCARDVPR!
Big Baby
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Duo E8400 Wolfdale 3.0 Ghz Asrock P45R2000 WiFi 460 GTX 6GB Patriot Viper DDR3 1333 (2x1GB and 2x2GB) 
Hard DriveOptical DriveOSMonitor
Kingston 64GB SSD, 1TB Hitachi and 3 160GB drives ASUS dual layer SATA II DVD burner Windows 7 Pro 64 Bit and a few virtual machines ;) Hanns.G Hi221D 22" LCD Widescreen 
KeyboardPowerCaseMouse
standard junker nothin' fancy. Yet... HIPER 730 W Rosewill Conqueror Logitech Trackball (TrackMan is the model I think) 
Mouse Pad
The Desk! 
  hide details  
Reply
Big Baby
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Duo E8400 Wolfdale 3.0 Ghz Asrock P45R2000 WiFi 460 GTX 6GB Patriot Viper DDR3 1333 (2x1GB and 2x2GB) 
Hard DriveOptical DriveOSMonitor
Kingston 64GB SSD, 1TB Hitachi and 3 160GB drives ASUS dual layer SATA II DVD burner Windows 7 Pro 64 Bit and a few virtual machines ;) Hanns.G Hi221D 22" LCD Widescreen 
KeyboardPowerCaseMouse
standard junker nothin' fancy. Yet... HIPER 730 W Rosewill Conqueror Logitech Trackball (TrackMan is the model I think) 
Mouse Pad
The Desk! 
  hide details  
Reply
post #7 of 17
Thread Starter 
Quote:
Originally Posted by ALUCARDVPR View Post
Here you go. Using null you can suppress the "Press any key to continue . . ." prompt of Pause and use echo to place your own text at that location.

Code:
echo Press any key to return to the main menu.
pause > nul
goto start
Thank you, that worked really well.

I have another problem now.

I added the following lines of code, to detect whether the batch file was being run as an administrator (and act dependingon the result)

Code:
OPENFILES > nul
IF %ERRORLEVEL%==0 (goto :start) ELSE (goto :notadmin)
Since the OPENFILES command requires admin priviledges, it will return ERRORLEVEL = 1 if the file is not being ran as an admin. And thus it will goto notadmin (or start if it is being ran as admin)

It works fine as a batch file, but when I convert it to an exe application it never works. Any ideas?
post #8 of 17
Quote:
Originally Posted by kiwiasian View Post
It works fine as a batch file, but when I convert it to an exe application it never works. Any ideas?
Are you using C:\\Windows\\System32\\iexpress.exe to "convert" it?

It needs to have cmd.exe /C run.bat so that it runs with the system environment.
Edited by ALUCARDVPR - 8/11/11 at 1:47pm
post #9 of 17
Thread Starter 
Quote:
Originally Posted by ALUCARDVPR View Post
Are you using C:\\Windows\\System32\\iexpress.exe to convert it?
I am using Bat To Exe Converter listed here http://www.computerhope.com/dutil.htm

I can try iexpress and see what happens
post #10 of 17
Quote:
Originally Posted by kiwiasian View Post
I am using Bat To Exe Converter listed here http://www.computerhope.com/dutil.htm

I can try iexpress and see what happens
Can you post your full code?

There are some batch commands that don’t work at all or work differently.
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Need some help with batch file coding