Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

how to check if a service is running via cmd

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
13 replies to this topic

#1
XtremeMaC

XtremeMaC

    MSFN SuperB

  • Member
  • PipPipPipPipPipPipPipPipPipPip
  • 5,011 posts
  • Joined 13-October 03
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




How to remove advertisement from MSFN

#2
MCT

MCT

    MSFN Junkie

  • Member
  • PipPipPipPipPipPipPipPipPip
  • 3,244 posts
  • Joined 19-May 04
i think someone posted a commandfile on how 2 check the status of a service via command file, maybe have a look with the search?

i THINK it maybe was jdoe

http://www.msfn.org/...=34628&hl=start
Posted Image Posted Image
Windows 7 32Bit 2GB Ram 120GB HDD (Laptop), Windows 8 4GB Ram 1TB HDD (Desktop) Windows XP SP3 VM with enhancements!

#3
oftentired

oftentired

    Member

  • Member
  • PipPip
  • 144 posts
  • Joined 25-August 04
From the WinXP command line:

SC (the non-MS explanation)

SC (the MS explanation)
Relationships are ours to make; we define them, day by day,
by who we choose to love and how we choose to love them.
And, by these choices, define ourselves. ~Richard N. Patterson

#4
XtremeMaC

XtremeMaC

    MSFN SuperB

  • Member
  • PipPipPipPipPipPipPipPipPipPip
  • 5,011 posts
  • Joined 13-October 03
thanks both!
how about a program to check in an executable is running? :D



#5
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,078 posts
  • Joined 13-October 04
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

#6
XtremeMaC

XtremeMaC

    MSFN SuperB

  • Member
  • PipPipPipPipPipPipPipPipPipPip
  • 5,011 posts
  • Joined 13-October 03
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



#7
jaclaz

jaclaz

    The Finder

  • Developer
  • 16,018 posts
  • Joined 23-July 04
You mean these:
http://www.jsiinc.co...0700/rh0770.htm
http://www.robvander.../processes.html
http://www.teamcti.c...iew/prcview.htm

jaclaz

#8
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,078 posts
  • Joined 13-October 04
@ 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


#9
oftentired

oftentired

    Member

  • Member
  • PipPip
  • 144 posts
  • Joined 25-August 04

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.
Relationships are ours to make; we define them, day by day,
by who we choose to love and how we choose to love them.
And, by these choices, define ourselves. ~Richard N. Patterson

#10
XtremeMaC

XtremeMaC

    MSFN SuperB

  • Member
  • PipPipPipPipPipPipPipPipPipPip
  • 5,011 posts
  • Joined 13-October 03
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



#11
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,078 posts
  • Joined 13-October 04
@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.

#12
rakeshmathur

rakeshmathur
  • Member
  • 2 posts
  • Joined 28-January 09
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

#13
rakeshmathur

rakeshmathur
  • Member
  • 2 posts
  • Joined 28-January 09
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

#14
ccyborg

ccyborg
  • Member
  • 1 posts
  • Joined 28-November 11
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=