Question : Dos script to control services

1.) Control Script:
I need a script that will manually start three different services. The three services must be started in a specific sequence. The services also take 10-20 (changes from time to time) minutes to completely start up so the next command must not be run before the previous service have completely started and has a status of "Started"
The bat file must look something like this:

cd\
sc \\192.168.2.163 start "Innovatrics Node 64-bit"

::(Only continue to next command once above have completely started-Unknown command or check?)

sc \\192.168.2.164 start "Innovatrics Dispatcher"

::(Only continue to next command once above have completely started-Unknown command or check?)

sc \\192.168.2.165 start "FaceTisMatcher"

2.) Monitoring Script:
I need a script which will monitor the above services and display something like:

Service:                          Status:
Innovatrics Node:           Started
Innovatrics Dispatcher   Started
FaceTisMatcher             Started

To get a service status the command is: sc \\192.168.2.163 query "Innovatrics Node 64-bit"
This output must then be used to give the status.

I would really appreciate if someone could help me with these two scripts.

Answer : Dos script to control services

try these:

========1==========

@ECHO OFF

SC \\192.168.2.163 start "Innovatrics Node 64-bit"
:WAITSERVICE1
ping -n 60 127.0.0.1 > nul
sc \\192.168.2.163 query "Innovatrics Node 64-bit" | FIND "STATE" | FIND "RUNNING"
IF ERRORLEVEL 1 GOTO WAITSERVICE1

SC \\192.168.2.164 start "Innovatrics Dispatcher"
:WAITSERVICE2
ping -n 60 127.0.0.1 > nul
sc \\192.168.2.164 query "Innovatrics Dispatcher" | FIND "STATE" | FIND "RUNNING"
IF ERRORLEVEL 1 GOTO WAITSERVICE2

SC \\192.168.2.165 start "FaceTisMatcher"
:WAITSERVICE3
ping -n 60 127.0.0.1 > nul
sc \\192.168.2.165 query "FaceTisMatcher" | FIND "STATE" | FIND "RUNNING"
IF ERRORLEVEL 1 GOTO WAITSERVICE3

========2===========

@ECHO OFF
:CHECK
CLS
ECHO Service:                  Status:
sc \\192.168.2.163 query "Innovatrics Node 64-bit" | FIND "STATE" | FIND "RUNNING" > NUL
IF ERRORLEVEL 1 ECHO Innovatrics Node 64-bit   STOPPED
sc \\192.168.2.163 query "Innovatrics Node 64-bit" | FIND "STATE" | FIND "RUNNING" > NUL
IF ERRORLEVEL 0 ECHO Innovatrics Node 64-bit   started
sc \\192.168.2.164 query "Innovatrics Dispatcher" | FIND "STATE" | FIND "RUNNING" > NUL
IF ERRORLEVEL 1 ECHO Innovatrics Dispatcher    STOPPED
sc \\192.168.2.164 query "Innovatrics Dispatcher" | FIND "STATE" | FIND "RUNNING" > NUL
IF ERRORLEVEL 0 ECHO Innovatrics Dispatcher    started
sc \\192.168.2.165 query "FaceTisMatcher" | FIND "STATE" | FIND "RUNNING" > NUL
IF ERRORLEVEL 1 ECHO FaceTisMatcher            STOPPED
sc \\192.168.2.165 query "FaceTisMatcher" | FIND "STATE" | FIND "RUNNING" > NUL
IF ERRORLEVEL 0 ECHO FaceTisMatcher            started
ping -n 5 127.0.0.1 > nul
GOTO CHECK

====================

script 1 will start service, then wait 1 minute, check if it is started, wait another minute ... until service is started
please note: if service can't be started, the script will wait forever...

script 2 will check every 5 seconds and display status

Please let me note if it works.. I didn't test them :-)

- Nic
Random Solutions  
 
programming4us programming4us