Jump to content
Sign in to follow this  

System Down!

Recommended Posts

Hey guys,

I want to put together an app that will go through the network and check if a specific service is running on a machine. What I am thinking is a text file containing all the IP addresses to check. If the service is running, move onto the next machine. If not, notify via email or SMS then move onto the next machine. This process would loop every 5 minutes.

What I need help with is how do I check for a running service on a remote machine??? I haven't written an script yet so there is nothing to share. Just looking for some guidance...



Share this post

Link to post
Share on other sites


Scanning is one way of doing it. But it is a burden on the network traffic.

And sometime give you access permission problems.

An other way is :

1. Open the Services.msc

2. Go to the specific service

3. Open properties.


5. Fill the MAIL Script in Run program.

This way the computer will monitor itself and send mails when needed.



Share this post

Link to post
Share on other sites

Although I really like the approach of PTREX (didn't do it like this yet), I would like to present another way of doing these things..

you have a linux based (free) sollution called NAGIOS (google it) it can check online status of servers, check services, run applications/ scripts etc, it can send SMS's, the whole lot..

another microsoft sollution is Microsoft Operations Manager (MOM) I use version 2005 (2007 should be out allready also)

this cannot send SMS's, but it does have all the tools needed to do what you want. For every microsoft product (exchange server, windows 2003, indigo, sql,.....) there are management packs, these are plugins written by the development team of the specific product. As long as there is no MOM management pack for a new version of for example SQL, the release will not happen. You could also use MOM for monitoring of windows XP Computers, but using MOM for client monitoring is kinda lame.. it's like buying a 5000$ computer and only use it to play minesweeper..

if you want to script this yourself (is perfectly possible) you could even go as far as use ADSI to get all computers from an OU, and use WMI (win32_Service provider) to verify the service on every PC in the returned array of computers.. this could be done in less than 20 lines of code.

I also suggest using logfiles instead of mailing (spam tends to get ignored) a log file is more clear..

Share this post

Link to post
Share on other sites

here's an example using only scripts allready existing in microsoft helpfiles.. (took me 20 minutes)

all you need to adjust is the Active directory information..

$objConnection = ObjCreate("ADODB.Connection")
$objCommand =  ObjCreate("ADODB.Command")
$objConnection.Provider = "ADsDSOObject"
$objConnection.Open("Active Directory Provider")
$objCommand.ActiveConnection = $objConnection
$objCommand.CommandText = _
    "Select Name, Location, operatingSystemVersion from 'LDAP://DC=fabrikam,DC=com'" _
       & " where objectClass='computer' and operatingSystemVersion = '5.1 (3600)'"  
$objCommand.Properties("Page Size") = 1000
$objCommand.Properties("Timeout") = 30 
$objCommand.Properties("Searchscope") = $ADS_SCOPE_SUBTREE
$objCommand.Properties("Cache Results") = False 
$objRecordSet = $objCommand.Execute
    $tmp2 =         "Computer Name: "   & $objRecordSet.Fields("Name").Value        & @CRLF
    $tmp2 = $tmp2 & "Location: "        & $objRecordSet.Fields("Location").Value    & @CRLF
  Until $objRecordSet.EOF

Func get_Service_Info($strComputer)
; $strComputer = "."
$UserName = ""
$Password = ""
$SWBemlocator = ObjCreate("WbemScripting.SWbemLocator")
$objWMIService = $SWBemlocator.ConnectServer($strComputer,"root\CIMV2",$UserName,$Password)
$colItems = $objWMIService.ExecQuery('Select * from Win32_Service where DisplayName="Net Logon"')

For $objItem in $colItems
    $tmp =         "Caption: "      & $objItem.Caption      & @CRLF
    $tmp = $tmp &  "Description: "  & $objItem.Description  & @CRLF
    $tmp = $tmp &  "DisplayName: "  & $objItem.DisplayName  & @CRLF
    $tmp = $tmp &  "ExitCode: "     & $objItem.ExitCode     & @CRLF
    $tmp = $tmp &  "InstallDate: "  & $objItem.InstallDate  & @CRLF
    $tmp = $tmp &  "Name: "         & $objItem.Name         & @CRLF
    $tmp = $tmp &  "PathName: "     & $objItem.PathName     & @CRLF
    $tmp = $tmp &  "ProcessId: "    & $objItem.ProcessId    & @CRLF
    $tmp = $tmp &  "Started: "      & $objItem.Started      & @CRLF
    $tmp = $tmp &  "StartMode: "    & $objItem.StartMode    & @CRLF
    $tmp = $tmp &  "State: "        & $objItem.State        & @CRLF
    $tmp = $tmp &  "Status: "       & $objItem.Status       & @CRLF
    $tmp = $tmp &  "--------------------------------------------------------"

; MsgBox(0,"",$tmp)
; log instead of messagbox..

Func LogMsg($Msg)
FileWriteLine("c:\logfiles\ServiceInfo.txt", $Msg)

Share this post

Link to post
Share on other sites

last reply from me in this thread..

you can also look into the windows native sc.exe command..

        SC is a command line program used for communicating with the
        NT Service Controller and services.
        sc <server> [command] [service name] <option1> <option2>...

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.

  • Create New...