Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I script to see if Exchange server is running

Status
Not open for further replies.

VantiveGuy

Programmer
Mar 10, 2008
4
BE
I have a virtual machine that is set up to start an outlook session every 15 minutes and process mails from shared mailboxes. However, sometimes the Exchange server goes down over weekends for mtce, and when the schedule starts Outlook there is a message box shown and Outlook is stopped until I go into the machine, clear the error message and close Outlook.
As this is meant to be an unattended function I need to check in my startup script if exchange server is running. Is this possible? I am using the scheduler to start a script as shown below.

On Error Resume Next
Set olkApp = GetObject(,"Outlook.Application")
Set oShell = CreateObject("WScript.Shell")
If TypeName(olkApp) <> "Application" Then
iRet = oShell.Run ("outlook.exe /autorun Application_Startup", 1, True)
End If

In the above I need a test to make sure exchange server is running. Any ideas?

Thanks you.
 
I'm not good with windows scripting, but could you should be able to use telnet to connect to the exchange server. If you get a response, it's up; if not, it's down.
 
In theory, you could check and see if the appropriate services are running on Exchange via sc.exe, but you'd have to parse the results.

The Exchange server shouldn't be down for maintenance very often, or for very long. Can't recall the last time I had an Exchange server offline for more than just a reboot.

Pat Richard
Microsoft Exchange MVP
Contributing author Microsoft Exchange Server 2007: The Complete Reference
 
Thanks for the tips folk. Actually, I have already tried the telnet approach. in my script I am doing a Telnet to the exchange server, and seeing a connected response, but the CMD window remains open and I have to manually "Quit" to exit.
I even tried to send the 'Quit" by SendKeys but with no success. This is what I did :
Set oShell = CreateObject("WScript.Shell")
iRet = oShell.Run ("telnet MyExchangeServerName 25", 1, False)
WScript.Sleep 10
oShell.SendKeys "Quit"
WScript.Quit
Neither the Sendkeys or the WScript.Quit closed the CMD session, though the response was that the server was in 'ready' status, so it's a step forward :)
Maybe I can redirect the output to a file and parse it, but how do I close the CMD window after getting the response?
Thanks again for you advice.



 
Hi Guys,

Just found that I can't even redirect the output of the Telnet command! Maybe because Telnet leaves an open CMD window. Either way, when I redirect output from the Telnet command I end up with an empty file.
AAaaarrrrrghhhhh! Any ideas?
 
Hi All,

Well, finally I gave up using Telnet to see if Exchange Server was running. Instead I found a Microsoft program called PortQry, which is a simple executeable that CAN have output redirected and which confirms that Exchange Server is listening on the port and that it is in Ready status. This was exactly what I needed.
The link to find this is :
Thanks for your inout.
 
But all that does is verify that the SMTP service is running (which, in 2003, is part of Windows, not Exchange). It doesn't tell you if the Information Store, System Attendant, or any of the other Exchange specific services are running.

Pat Richard
Microsoft Exchange MVP
Contributing author Microsoft Exchange Server 2007: The Complete Reference
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top