Hello all....

A complete VBScript newbie here. Pardon any stupid questions that may
follow, but I am hoping to learn something new.

I am tasked with monitoring several services on a server on a daily basis. I
was thinking about a .vbs script that could be called from a batch file ( if
that is even possible ). I would like for this script to create a simple
text file list of all services that are running on the server including the
status of the service ( stopped, started, etc... ).

If this possible, any hints as to how to go about writing this script would
be greatly appreciated.


Thank you,

Mike Minor

Re: Script to monitor services running by Torgeir

Torgeir
Wed Nov 03 15:24:47 CST 2004

Mike Minor wrote:

> I am tasked with monitoring several services on a server on a daily basis. I
> was thinking about a .vbs script that could be called from a batch file ( if
> that is even possible ). I would like for this script to create a simple
> text file list of all services that are running on the server including the
> status of the service ( stopped, started, etc... ).
Hi

Some starting points:

In the link below is a script that reads server names from servers.txt,
and for each server compares running services with a list of services
(the service name) from the file services.txt. Connection errors and
the status of the services (Running/Not started) are reported in the
file StatusServices.txt.

Subject: Re: Do you have a script to check if an NT service is
present on a machine
http://groups.google.com/groups?selm=3D8F5402.AB59D491%40hydro.com


A couple of other services check examples:

Subject: Re: Monitoring Services and taking action
http://groups.google.com/groups?selm=404F5E71.C9DD5EFA%40hydro.com

Subject: Re: Check state of services
http://groups.google.com/groups?selm=3E83986E.9EEE0304%40hydro.com

Subject: Re: VBS - Services Running? - Please help.
http://groups.google.com/groups?selm=3E84D2AC.4496450D%40hydro.com



WSH 5.6 documentation (local help file) can be downloaded from here
if you haven't got it already:
http://msdn.microsoft.com/downloads/list/webdev.asp


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx

Re: Script to monitor services running by Mike

Mike
Thu Nov 04 06:55:43 CST 2004

Thank you very much.. I think I will be able to take it from here. Your help
is greatly appreciated.

Again, thank you,

Mike Minor
Z-Code Systems, Inc.



Re: Script to monitor services running by Mike

Mike
Thu Nov 04 09:10:52 CST 2004

Torgeir...

The script you provided is exactly what I need. Thank you very much.

I had a little trouble with the list of services to be checked. It stated
that I should create a text file services.txt. When I ran the script it
would give an error of No services found and I found that in the name of the
array of services needed to be changed ever so slightly in the following
line:

oServer.Filter = Array("service") - to - oServer.Filter =
Array("services")

When running the script however, I am receiving a Syntax error in line 78,
character 5.

I believe that the line of code that is erroring off is the "Set
oServer...." line listed below, but I can't seem to detect the syntax
problem:

For Each sServer In aServers
LogStatus Now & " ---- Starting " & sServer & " ----"

' test with ping
If IsConnectible(sServer,"","") Then
Set oServer = GetObject("WinNT://" & sServer)
oServer.Filter = Array("services")

Can you identify the syntax error?

Is there a free or low cost VBScript editor available that will detect
syntax errors? I have also attached the script as I have modified it ( very
small changes to the directory where servers.txt and services.txt and
statusservices.txt are stored.)

Thank you,

Mike Minor
Z-Code Systems, Inc.

ps....please pardon the double posting. I seem to have started a new thread
the first time I tried to post this message....





Re: Script to monitor services running by Torgeir

Torgeir
Thu Nov 04 14:28:15 CST 2004

Mike Minor wrote:

> Torgeir...
>
> The script you provided is exactly what I need. Thank you very much.
>
> I had a little trouble with the list of services to be checked. It stated
> that I should create a text file services.txt. When I ran the script it
> would give an error of No services found and I found that in the name of the
> array of services needed to be changed ever so slightly in the following
> line:
>
> oServer.Filter = Array("service") - to - oServer.Filter =
> Array("services")
>

Array("service") works for me, Array("services") does not,
this on a Win2k SP2 computer.

This works for me:

'--------------------8<----------------------
Set oWshNet = CreateObject("WScript.Network")
sServer = oWshNet.ComputerName

Set oServer = GetObject("WinNT://" & sServer)
oServer.Filter = Array("service")

For Each oService in oServer
WScript.Echo oService.Name
Next
'--------------------8<----------------------

Ahh, testing on a WinXP SP2 computer, bot "service" and
"services" work.



> When running the script however, I am receiving a Syntax error in line 78,
> character 5.
>
> I believe that the line of code that is erroring off is the "Set
> oServer...." line listed below, but I can't seem to detect the syntax
> problem:
>
> For Each sServer In aServers
> LogStatus Now & " ---- Starting " & sServer & " ----"
>
> ' test with ping
> If IsConnectible(sServer,"","") Then
> Set oServer = GetObject("WinNT://" & sServer)
> oServer.Filter = Array("services")
>
> Can you identify the syntax error?

Not really, if I run the script that was attached to your other
post that was ending up as separate thread, I have no errors,
and results are written to the StatusServices.txt file.


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx