ca143508 Posted September 28, 2007 Share Posted September 28, 2007 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... Cheers Mike. Link to comment Share on other sites More sharing options...
ptrex Posted September 28, 2007 Share Posted September 28, 2007 @ca143508 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. 4. Go to RECOVERY 5. Fill the MAIL Script in Run program. This way the computer will monitor itself and send mails when needed. Regards ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
lordofthestrings Posted September 28, 2007 Share Posted September 28, 2007 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.. Link to comment Share on other sites More sharing options...
lordofthestrings Posted September 28, 2007 Share Posted September 28, 2007 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.. expandcollapse popuponst $ADS_SCOPE_SUBTREE = 2 $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 $objRecordSet.MoveFirst Do $tmp2 = "Computer Name: " & $objRecordSet.Fields("Name").Value & @CRLF $tmp2 = $tmp2 & "Location: " & $objRecordSet.Fields("Location").Value & @CRLF LogMsg($tmp2) get_Service_Info($objRecordSet.Fields("Name").Value) $objRecordSet.MoveNext 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 & "--------------------------------------------------------" Next ; MsgBox(0,"",$tmp) ; log instead of messagbox.. LogMsg($tmp) EndFunc Func LogMsg($Msg) FileWriteLine("c:\logfiles\ServiceInfo.txt", $Msg) FileClose("c:\logfiles\ServiceInfo.txt") EndFunc Link to comment Share on other sites More sharing options...
lordofthestrings Posted September 28, 2007 Share Posted September 28, 2007 last reply from me in this thread.. you can also look into the windows native sc.exe command.. DESCRIPTION: SC is a command line program used for communicating with the NT Service Controller and services. USAGE: sc <server> [command] [service name] <option1> <option2>... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now