Jump to content

how to check if a service is running via cmd


XtremeMaC

Recommended Posts

hi there

is there such utility that will check if a service is running via command prompt?

so it'll check the memory for running services, also is there a program to check for running apps via command prompt?

well i've actually found some programs but how can i modify them so that they return 0's 1's or true false etc..

1 tool from sysinternals psservice.

thanks

Link to comment
Share on other sites


You could check the state with TASKLIST and close it with TASKKILL, or probably use TASKKILL on its own. For a clue a look at /FI (Filter_Name) Status, Operators eq, ne and Values RUNNING|NOT RESPONDING

Link to comment
Share on other sites

well okay better yet lemme explain what i'm trying to do :D

i've perfect disk installed, it has 2 services and 1 exe to get it running.

services:

pdengine

pdsched

executable:

perfectdisk.exe

starting the app:

check if pdsched is running, if its running do nothing, else start the service

check if pdengine is running, if its running do nothing, else start the service

check if both services are running if so then start the executable if its not already running.

stopping the app:

net stop pdengine /y

net stop pdsched

taskkill /f /im perfectdisk.exe

now the stopping part is easy but i've problems on the starting part, can anyone help? thanks

Link to comment
Share on other sites

@ XtremeMaC

I'm only playing with batch files, but how about trying something like this!

You will need to put the correct path in the SET Proc line, and quotes will only be needed if there are spaces in the path

@ECHO OFF
SETLOCAL

SET Proc="%ProgramFiles%\subdirectory\perfectdisk.exe"
SET Svcs=pdengine pdsched

FOR %%a IN (%Svcs%) DO SC query %%a | FIND /i "RUNNING"
IF ERRORLEVEL 1 SC start %%a

TASKLIST | FIND /i "perfectdisk.exe"
IF ERRORLEVEL 1 START "" %Proc%

ENDLOCAL
GOTO :EOF

Link to comment
Share on other sites

thanks both!

how about a program to check in an executable is running? :D

There is a little tiny program called PV.EXE that comes in the ZIP file for PrcView 3.7.3.1 which will do exactly what you are trying to do. It returns error levels for use in batch files. In the ZIP file the two files you would be interested in are PV.EXE and PV.TXT. The text file is very complete.

Link to comment
Share on other sites

  • 3 years later...
  • 2 years later...

a script that try to stop tomcat service and retry if still running until retry limit is not reached



@echo off

SET CATALINA_HOME=C:\SAP BusinessObjects\Tomcat6
SET /A RETRYMAX=10
SET /A NBRETRY=1
SET /A WAITBEFORERETRY=3

:STOP
echo.stopping...
CALL "%CATALINA_HOME%\bin\shutdown.bat"

sc query "BOEXI40Tomcat" | find /i "RUNNING"
IF ERRORLEVEL 1 GOTO END

:RETRY
IF [%NBRETRY%]==[%RETRYMAX%] GOTO END
echo.
echo.------------------
echo. %NBRETRY%
echo. wait %WAITBEFORERETRY%sec
echo.------------------
echo.
SET /A NBRETRY+=1
Timeout /T %WAITBEFORERETRY% /NOBREAK
GOTO STOP

:END
echo.END
SET RETRYMAX=
SET NBRETRY=

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...