0

I am attempting to check thatthe service ACR BRIDGE is running and start it is not.

cd C:\Users\ET012364\Desktop\PSEXEC
psservice \\ccapps query "ACR BRIDGE"
pause

I understand that I could achieve this using a combination of error levels and the stop start commands. However, I am more interested in knowing how to manipulate the data returned by this command.

SERVICE_NAME: ACRBridge
DISPLAY_NAME: ACR Bridge
ACR Bridge for controlling both Master and Standby Collect Corp Recorders.  If t
he service is down, it will restart after one minute.
        GROUP             : someorder
        TYPE              : 10 WIN32_OWN_PROCESS
        STATE             : 4  RUNNING
                               (STOPPABLE,NOT_PAUSABLE,ACCEPTS_SHUTDOWN)
        WIN32_EXIT_CODE   : 0  (0x0)
        SERVICE_EXIT_CODE : 0  (0x0)
        CHECKPOINT        : 0x0
        WAIT_HINT         : 0 ms

This is what is returned and what I want to extract the STATE value from.

This is the code I ended up using. I think it's the most simple of the solutions.

 @echo off
 cd C:\Users\ET012364\Desktop\PSEXEC


 psservice \\ccapps query "ACR BRIDGE" | find "RUNNING"

 if "%ERRORLEVEL%"=="0" (
     echo ACR BRIDGE is running
 ) else (
     echo ACR BRIDGE on CCAPPS is not running
     pause
 )


 psservice \\ccapps query "DIALERMESSAGEMONITOR"| find "RUNNING"

 if "%ERRORLEVEL%"=="0" (
     echo Dialer MessageMonitor is running
 ) else (
     echo Dialer MessageMonitor on CCAPPS is not running
     pause
 )
  • I believe that the solution is using the errorlevel of the following command. '>psservice \\ccapps query "ACR BRIDGE" | FIND " STATE"' | 'FIND "RUNNING"' – user2271967 May 22 '13 at 18:18

2 Answers2

0

try this:

for /f "tokens=1-3 delims=: " %%i in ('psservice \\ccapps query "ACR BRIDGE" 2^>nul') do if "%%i"=="STATE" set "state=%%j %%k"
REM                        ^----put a tabstop after the ":"
echo %state%
Endoro
  • 37,015
  • 8
  • 50
  • 63
0

This polishes the comment above in reply to your question. It is untested.

@echo off
cd /d "C:\Users\ET012364\Desktop\PSEXEC"
psservice \\ccapps query "ACR BRIDGE" | FIND "STATE" | FIND "RUNNING" >nul || net start "ACR BRIDGE"
foxidrive
  • 40,353
  • 10
  • 53
  • 68