• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 622
  • Last Modified:

menus within batch files

Basically I want a batch file to be able to start and stop services running on windows xp pro.

It should display the following list of options

1 Start LogMeIn
2 Stop LogMeIn
3 Start FTP
4 Stop FTP

I would like it to use the NET command to start and stop services.
0
schoi_ukuk
Asked:
schoi_ukuk
  • 4
  • 2
2 Solutions
 
InteractiveMindCommented:
try this:


@echo off
title Service Manager
:start
set choice=
cls
echo.
echo Choose an option:
echo.
echo   1  -  Start LogMeIn
echo   2  -  Stop LogMeIn
echo   3  -  Start FTP
echo   4  -  Stop FTP
echo.
:choice
set /p choice="Enter your choice: "
if /i "%choice%"=="1" goto :start_logMeIn
if /i "%choice%"=="2" goto :stop_logMeIn
if /i "%choice%"=="3" goto :start_ftp
if /i "%choice%"=="4" goto :stop_ftp
echo Invalid input.
goto :choice

:start_logMeIn
cls
echo.
net start LogMeIn
echo Started service "LogMeIn".
ping -n 2 localhost >nul
goto :start

:stop_logMeIn
cls
echo.
net stop LogMeIn
echo Stopped service "LogMeIn".
ping -n 2 localhost >nul
goto :start

:start_ftp
cls
echo.
net start FTP
echo Started service "FTP"
ping -n 2 localhost >nul
goto :start

:stop_ftp
cls
echo.
net stop FTP
echo Stopped service "FTP".
ping -n 2 localhost >nul
goto :start



Hope that helps,
Rob.
0
 
InteractiveMindCommented:
Alternatively, if there's at all likely to be errors in the process, and you need to catch the output, then replace these lines in the code:

   echo Stopped service "FTP".
   ping -n 2 localhost >nul

with:

   echo.
   echo Press any key to return to the beginning . . .
   pause >nul
0
 
softplusCommented:
here's an idea for the menu as a .bat file:

echo 1 Start LogMeIn
echo 2 Stop LogMeIn
echo 3 Start FTP
echo 4 Stop FTP
set /P choice=Which one?
if "%choice%"=="1" goto DoOne
if "%choice%"=="2" goto DoTwo
if "%choice%"=="3" goto DoThree
if "%choice%"=="4" goto DoFour
goto Done
:DoONe
bla bla
goto Done
:DoTwo
bla bla
goto done
:DoThree
net start ftp
goto done
:DoFour
net stop ftp
goto done
:done

More or less - fill in the blanks :)
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
softplusCommented:
Must be correct if two people get the same result :))
0
 
InteractiveMindCommented:
Near enough.  ^_^
0
 
InteractiveMindCommented:
I am a little bit curious to why Softplus's answer was accepted..? Not only does my do the same (and more; including support for invalid input, as well as a cleaner layout), but my solution was posted first..

It just baffles me a little. :o\
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now