#1 01 Dec 2011 22:03

prakash82x
Member
Registered: 03 Mar 2009
Posts: 22

One Batch script to start or stop services

Hello,
I am trying to create a batch file which can start or stop services depending on the input provided at the time of executing the script.

i tried using the below script:

@echo off
choice /n /c:12 Please choose 2 for Stopping, 1 for Starting
if errorlevel 2 goto Stop
if errorlevel 1 goto Start

:Start
net Start "VMware USB Arbitration Service"
net Start "VMware Authorization Service"
net Start "VMware DHCP Service"
net Start "VMware NAT Service"
net Start "VMware Workstation Server"

:Stop
net Stop "VMware Workstation Server"
net Stop "VMware USB Arbitration Service"
net Stop "VMware Authorization Service"
net Stop "VMware DHCP Service"
net Stop "VMware NAT Service"


Now when entered 1 upon prompting, for starting the services, it starts them but at the same time once all the services are started it stops them  also (processes :Stop label a well)

Please help.

Offline

#2 02 Dec 2011 05:14

RG
Member
From: Minnesota
Registered: 18 Feb 2010
Posts: 321

Re: One Batch script to start or stop services

The CHOICE command was introduced in MS-DOS 6.  As of Windows NT 4, CHOICE is no longer a part of the standard distribution.  Roll your own with something like this:

@echo off

:Select
cls
ECHO.Start/Stop Services
set /p Selection=Enter 1 to start, 2 to stop^>
echo.
if "%Selection%"=="1" goto :Start
if "%Selection%"=="2" goto :Stop

color cf
echo.Error! Enter a valid choice.
pause
color 07
goto :Select

:Start
echo.Starting services
rem Start services here
pause
goto :eof

:Stop
echo.Stopping services
rem Stop services here
pause
goto :eof

Last edited by RG (02 Dec 2011 05:16)


CMD and InstallShield

Offline

#3 05 Dec 2011 17:49

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 939

Re: One Batch script to start or stop services

@echo off
choice /n /c:12 Please choose 2 for Stopping, 1 for Starting
if errorlevel 2 goto Stop
if errorlevel 1 goto Start

:Start
net Start "VMware USB Arbitration Service"
net Start "VMware Authorization Service"
net Start "VMware DHCP Service"
net Start "VMware NAT Service"
net Start "VMware Workstation Server"
goto :EOF

:Stop
net Stop "VMware Workstation Server"
net Stop "VMware USB Arbitration Service"
net Stop "VMware Authorization Service"
net Stop "VMware DHCP Service"
net Stop "VMware NAT Service"
goto :EOF

cmd | *sh  | KiX | AutoIT3 | PowerShell | Puppet

Offline

Board footer

Powered by FluxBB