Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, register and become a site sponsor/subscriber and ads will be disabled automatically. 



Sign in to follow this  
XtremeMaC

how to check if a service is running via cmd

Recommended Posts

XtremeMaC    0

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

Share this post


Link to post
Share on other sites

Yzöwl    30

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

Share this post


Link to post
Share on other sites
XtremeMaC    0

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

Share this post


Link to post
Share on other sites
Yzöwl    30

@ 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

Share this post


Link to post
Share on other sites
oftentired    0
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.

Share this post


Link to post
Share on other sites
XtremeMaC    0

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

Share this post


Link to post
Share on other sites
Yzöwl    30

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

Share this post


Link to post
Share on other sites
ccyborg    0

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=

Share this post


Link to post
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

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×