Thursday, 15 August 2013

Bat file to query service status with options -



Bat file to query service status with options -

i have query check status of service , give options based on status having issues in error portion. seems work of there not alternative chosen. works first time. can see have 3 options if select alternative 4 defaults alternative 1. please take , explain missing.

@echo off echo status of mgt scheme manager service goto welcome echo. :welcome sc query mgtsm | findstr /i "state" echo do? echo 1. start service echo 2. stop service echo 3. exit set /p choice=select choice. if '%choice%'=='' echo "%choice%" not valid please seek again. if '%choice%'=='1' goto start service if '%choice%'=='2' goto stop service if '%choice%'=='3' goto exit echo. :start service net start mgtsm goto welcome :stop service net stop mgtsm goto welcome :exit exit

set /p not touch variable, if come in nil (just enter). hence should delete variable before:

:welcome .... set "choice=" //this deletes %choice% set /p "choice=select choice: " if '%choice%'=='1' goto startservice if '%choice%'=='2' goto stopservice if '%choice%'=='3' goto exit rem line reached, when of "if ... goto" above failed echo not valid input: "%choice%" goto welcome ...

labels , goto have problem spaces: goto start service go "start", ignoring "service". same labels: :start service, label :start, "service" ignored.

batch-file

No comments:

Post a Comment