Any way to find if a service is running or not

Posted on 2007-08-11
Last Modified: 2010-03-05

I want a script to query all machines in a file if a service is running or not.It should pop a box for the service name.

Question by:bsharath
    1 Comment
    LVL 26

    Accepted Solution

    :: ================
    :: ================
    :: * To run this script you must have domain administrators rights.
    :: * This script require "Computers.txt" file on C: drive root from where it will pick computer names.
    :: * Copy and Paste following script into notepad and save it with any name having .bat extension.
    :: * Successul run will generate 'SrvcStatus.txt' file on C: drive root.
    :: Batch Script Start

    @Echo Off
    SETLOCAL EnableDelayedExpansion
    SET /P SrvceName=Enter Service Name:  

    IF EXIST C:\SrvcStatus.txt DEL /F /Q C:\SrvcStatus.txt
    IF NOT EXIST C:\Computers.txt Goto ShowErr
    FOR %%R IN (C:\Computers.txt) Do IF %%~zR EQU 0 Goto ShowErr
    FOR /F %%c IN ('Type Computers.txt') Do (
        Echo Processing: %%c
          PING -n 1 -w 1000 %%c|Find /I "TTL" >NUL
          IF NOT ErrorLevel 1 (
                SC \\%%c Query %SrvceName% | Find /I "RUNNING" >NUL
                IF ErrorLevel 1 (Echo !SrvceName! Service is NOT Running on: %%c >>C:\SrvcStatus.txt) Else (
                Echo !SrvceName! Service is Running on: %%c >>C:\SrvcStatus.txt)
          )ELSE (Echo %%c: Not able to connect >>C:\SrvcStatus.txt)

    Goto EndScript
    Echo "C:\Computers.txt" file does not exist or file is empty!
    :: Batch Script End

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    The way I use Experts Exchange to assist me in analyzing and diagnosing a problem is I first enter a Verbose Question at Experts Exchange like: Office 2007 will hang when opening and saving files I then launch WordPad (any text editor will do) an…
    This is my 3rd article on SCCM in recent weeks, the 1st ( dealing with installat…
    Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now