[THIN] Re: Problems with using WSH/WMI to check services on a Server

  • From: Spencer Sun <ssunssun@xxxxxxxxx>
  • To: thin@xxxxxxxxxxxxx
  • Date: Mon, 4 Oct 2004 19:25:51 -0500

Jon,
Without actually following the logic, I found 10 missing End If statements.

The last bunch of Else IF are missing the End If statement.  Each If
or Else If requires it's own End If statement to close the loop.

I threw 10 End If statements at the end of the script and I received
no compilation errors.

HTH,

Spencer


----- Original Message -----
From: Spriggs Jon <jon.spriggs@xxxxxxxxxxxxxx>
Date: Mon, 4 Oct 2004 23:58:35 +0100
Subject: [THIN] Problems with using WSH/WMI to check services on a Server
To: windows2000@xxxxxxxxxxxxx, thin@xxxxxxxxxxxxx


Hi,
 
I wonder if anyone can help me. I've been toying with the enclosed
script, and I can't make it work... I get so far through the script
and then it starts throwing up bugs...
 
Now, I know my knowledge of VBS, WSH and WMI is a little on the slow
side, but I've checked out all the If / Then / Else If / Else / End If
loops, and all the For / Next loops, and it doesn't *look* like I've
missed anything... have I? I'm using Windows 2k on the desktop
(although this is on an XP laptop as well) and 2k on the server.
 
I get an error message:
 
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
 
D:\pingserver.vbs(130, 7) Microsoft VBScript compilation error: Expected 'End'
 
If anyone can tell me how to cycle through the quotas set on a windows
2000 server with WMI and feed that into a text file, I'd be really
grateful - same with how to backup and reset event logs.
 
Thanks,
 
Jon Spriggs 
-- 
The presence of a "Fujitsu" address does not imply or assume that
Fujitsu Services, Fujitsu or any other company containing the Fujitsu
name uses or endorses this product. This email is purely a personal
opinion.
 
--- PingServer.vbs ---
 
On Error Resume Next
 
Dim sHost
Dim sTarget
Dim iSVRResp
Dim iTSCount
Dim iDHCPCount
Dim iDFSCount
Dim iFRSCount
 
sHost = "."
sTarget = "MyW2KServer"
iSVRResp = 0
iTSCount = 0
iDHCPCount = 0
iDFSCount = 0
iFRSCount = 0
 
Set cPingResults = GetObject("winmgmts://" & sHost & "/root/cimv2")._
      ExecQuery("SELECT * FROM Win32_PingStatus WHERE Address = '" +
sTarget + "'")
 
For Each oPingResult In cPingResults
 If oPingResult.StatusCode = 0 Then
 
  If oPingResult.ResponseTime > 100 Then 
   iSVRResp = 1 
  Else 
   iSVRResp = 2 
  End If
 
  Set cServiceTS = GetObject("winmgmts://" & sTarget & "/root/cimv2")._
    ExecQuery("SELECT * FROM Win32_Service WHERE DisplayName =
'Terminal Services'")
 
  For Each oServiceTS in cServiceTS
   If oServiceTS.Started = False Then
    iTSCount = 1
   Else
    iTSCount = 2
   End If
 
  Next
  
  Set cServiceDHCP = GetObject("winmgmts://" & sTarget & "/root/cimv2")._
    ExecQuery("SELECT * FROM Win32_Service WHERE DisplayName = 'DHCP Server'")
  
  For Each oServiceDHCP in cServiceDHCP
   If oServiceDHCP.Started = False Then
    iDHCPCount = 1
   Else
    iDHCPCount = 2
   End If
 
  Next
  
  Set cServiceDFS = GetObject("winmgmts://" & sTarget & "/root/cimv2")._
    ExecQuery("SELECT * FROM Win32_Service WHERE DisplayName =
'Distributed File System'")
  
  For Each oServiceDFS in cServiceDFS
   If oServiceDFS.Started = False Then
    iDFSCount = 1
   Else
    iDFSCount = 2
   End If
 
  Next
 
  Set cServiceFRS = GetObject("winmgmts://" & sTarget & "/root/cimv2")._
    ExecQuery("SELECT * FROM Win32_Service WHERE DisplayName = 'File
Replication Service'")
 
  For Each oServiceFRS in cServiceFRS
 
   If oServiceDFS.Started = False Then
    iFRSCount = 1
   Else
    iFRSCount = 2
   End If
 
  Next
 
 Else
  iSVRResp = 0
 End If
Next
 
If iSVRResp = 2 AND iTSCount = 2 AND iDHCPCount = 2 AND iDFSCount = 2
AND iFRSCount = 2 Then
 
 wscript.echo "Server running and all Services Running OK"
 
Else
 
 If iSVRResp = 0 Then
  wscript.echo "Outage: Server Down (" & sTarget & ")"
 Else If iSVRResp = 1 Then
  wscript.echo "Warning: Server Slow (" & sTarget & ")"
 Else If iSVRResp = 2 Then
  wscript.echo "Server responds OK (" & sTarget & ")"
 End If
 
 If iTSCount = 0 Then
  wscript.echo "Warning: Terminal Services Service Does Not Exist On
This Server (" & sTarget & ")"
 Else If iTSCount = 1 Then
  wscript.echo "Outage: Terminal Services Service Has Stopped (" & sTarget & ")"
 Else If iTSCount = 2 Then
  wscript.echo "Terminal Services Service OK (" & sTarget & ")"
 End If
 
 If iDHCPCount = 0 Then
  wscript.echo "Warning: DHCP Server Service Does Not Exist On This
Server (" & sTarget & ")"
 Else If iDHCPCount = 1 Then
  wscript.echo "Outage: DHCP Server Service Service Has Stopped (" &
sTarget & ")"
 Else If iDHCPCount = 2 Then
  wscript.echo "DHCP Server Service OK (" & sTarget & ")"
 End If
 
 If iDFSCount = 0 Then
  wscript.echo "Warning: DFS Service Does Not Exist On This Server ("
& sTarget & ")"
 Else If iDFSCount = 1 Then
  wscript.echo "Outage: DFS Service Service Has Stopped (" & sTarget & ")"
 Else If iDFSCount = 2 Then
  wscript.echo "DFS Service OK (" & sTarget & ")"
 End If
 
 If iFRSCount = 0 Then
  wscript.echo "Warning: FRS Service Does Not Exist On This Server ("
& sTarget & ")"
 Else If iFRSCount = 1 Then
  wscript.echo "Outage: FRS Service Service Has Stopped (" & sTarget & ")"
 Else If iFRSCount = 2 Then
  wscript.echo "FRS Service OK (" & sTarget & ")"
 End If
End If



-- 
Spencer Sun
ssun@xxxxxxxxx
ssun@xxxxxxxx
********************************************************
This Weeks Sponsor RTO Software
Do you know which applications are abusing your CPU and memory?
Would you like to learn? --   Free for a limited time!
Get the RTO Performance Analyzer to quickly learn the applications, users,
and time of day possible problems exist.
http://www.rtosoft.com/enter.asp?id=320
********************************************************** 
Useful Thin Client Computing Links are available at:
http://thin.net/links.cfm
***********************************************************
For Archives, to Unsubscribe, Subscribe or 
set Digest or Vacation mode use the below link:
http://thin.net/citrixlist.cfm

Other related posts: