'**************************************************************************
'
' Copyright (c) SAPIEN Technologies, Inc. All rights reserved
' This file is part of the PrimalScript 2011 Code Samples.
'
' File: SMTPQueueMonitor.vbs
'
' Comments:
' This script will query SMTP queues on an Exchange 2003 server
' and display queue sizes and message counts in an Internet
' Explorer Window. Any pending messages will be enumerated.
' The window will refresh by default every 60
' seconds. You can modify this by editing the iREFRESH constant
' and specifiying a value in milliseconds.
' The script will prompt you for a server name and alternate credentials.
' This tool is designed to be run from a Windows XP desktop. It uses WMI.
' Exchange management tools do not need to be installed.
' This version of the tool will only monitor queues. There are no features To
' clear queues or messages.
' Disclaimer: This source code is intended only as a supplement to
' SAPIEN Development Tools and/or on-line documentation.
' See these other materials for detailed information
' regarding SAPIEN code samples.
'
' THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
' KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
' IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
' PARTICULAR PURPOSE.
'
'**************************************************************************
On Error Resume Next
dim objIE
dim objLocator
dim objWMIService
dim colQueues
Dim objNetwork
Const wbemFlagReturnImmediately=&h10
Const wbemFlagForwardOnly=&h20
'refresh interval in Milliseconds
Const iREFRESH=60000
strTitle="SMTP Queue Monitor"
strNamespace="root\MicrosoftExchangeV2"
strQuery="Select * from Exchange_SMTPQueue"
strUsername=""
strPassword=""
Set objNetwork=CreateObject("WScript.Network")
strSrv=InputBox("What Exchange 2003 server do you want to monitor?",strTitle,"EXCHANGE01")
If strSrv="" Then WScript.Quit
If UCase(strSrv)<>UCase(objNetwork.ComputerName) Then
strUsername=InputBox("Enter in alternate credentials (ie domain\admin) or leave " &_
"BLANK to use current credentials.",strTitle,objNetwork.UserDomain & "\Administrator")
If strUsername<>"" Then
strPassword=InputBox("Enter alternate credential password for " &_
strUsername & ". This input box " &_
"will display the password in clear text.",strTitle,"P@ssw0rd")
End if
End If
Set objIE = CreateObject("InternetExplorer.Application")
objIE.navigate "about:blank"
objIE.ToolBar = False
objIE.AddressBar = False
objIE.Top = 25
objIE.Left = 25
objIE.Width = 450
objIE.Height = 450
objIE.Visible = True
objIE.menubar = False
objIE.StatusBar = False
objIE.Document.Body.Title = strTitle
blnRunning=True
'check if IE is running. If not, then exit
Do While blnRunning
t=objIE.Document.Body.Title
If Err.Number=0 then
RunQuery
WScript.Sleep iREFRESH
Else
blnRunning=False
End If
Loop
WScript.Quit
Sub RunQuery()
On Error Resume Next
strHTML="Querying SMTP Queues on " & UCase(strSrv) & "
"
objIE.document.body.innerHTML= strHTML
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
objLocator.Security_.ImpersonationLevel=3
objLocator.Security_.AuthenticationLevel=WbemAuthenticationLevelPktPrivacy
Set objWMI=objLocator.ConnectServer(strSrv,strNamespace,strUsername,strPassword)
Set colQueues=objWMI.ExecQuery(strQuery,"WQL",wbemForwardOnly+wbemFlagReturnImmediately)
strHTML="
| " & UCase(strSrv) &_ " " & strTitle & " |
| Link Name | " &_ "Size (bytes) | " &_ "Message Count | " strHTML=strHTML & " |
| " & queue.LinkName & " | " strHTML=strHTML & "" & queue.Size & " | " strHTML=strHTML & "" & queue.MessageCount & " | " strHTML=strHTML & "|
|   | " strHTML=strHTML & ""
strHTML=strHTML & " From: " & msg.Sender & " " strHTML=strHTML & " To: " & msg.recipients& " " strHTML=strHTML & " Size (bytes):" & msg.Size& " " strHTML=strHTML & " Received: " & ConvWMITime(msg.Received)& " " strHTML=strHTML & " Submitted: " & ConvWMITime(msg.Submission)& " " strHTML=strHTML & " | ||