Jump to content

how to check if a service is running via cmd


Recommended Posts

Posted

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


Posted

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

Posted

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

Posted

@ 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

Posted
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.

Posted

thanks all!!!

just saw this, dunno why i sometimes don't get reply notification via email

anyways thanks for all the usefull stuff. i'm so bad at this dos stuff. :D

Posted

@XtremeMaC

As I said that I was playing with batches, could you let me know if it works please. I may use a similar idea for something else, and would be grateful of the feedback.

  • 3 years later...
Posted

Maybe no one is looking for this anymore...but thid did not work when I used on Windows 2003. I am having trouble executing this line: IF ERRORLEVEL 1 SC start %%a

Can anyone help?

Thanks!

RM

Posted

Okay, I was able to get this to work, this is the final script I used:

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

IF ERRORLEVEL 1 SC start %%a)

the parentheses did the trick.

Thanks

RM

  • 2 years later...
Posted

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=

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...