Script for From The Field
The authors of the upcoming "Windows Server 2008 Terminal Services Resource Kit" asked me if I wanted to write a script for them for a section named "From The Field". I said sure! I based the script on one I wrote a long time ago, which you can access here. So the readers have the EXACT script that was published I'm putting this on my blog.
The purpose for this script is to tie the script to a particular event that might occur from Terminal Services. This capability is a new feature of the Windows Server 2008 Event Log Subsystem. If that event occurs, then this script is executed to send an email.
Now, the Resource Kit goes into detail of the event id that happens and how you actually do that tying together. Go buy it! :-)
Of course, there are multiple ways to skin this cat, but here is one for you to use.
'''----- script configuration area
Const strSMTPServer = "arvon.alpineskihouse.com"
Const strFrom = "firstname.lastname@example.org"
Const strTo = "email@example.com "
'''----- end configuration area
Dim objMail ' the CDO object
Dim objWSHNetwork ' windows-script-host network object
Dim strNetBIOSComputer ' the netbios name of our computer
''' get the NetBIOS computer name
Set objWSHNetwork = CreateObject ("WScript.Network")
strNetBIOSComputer = objWSHNetwork.ComputerName
Set objWSHNetwork = Nothing
''' do the real work to send the message
Set objMail = CreateObject ("CDO.Message")
objMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTPServer
objMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMail.From = strFrom
objMail.To = strTo
objMail.Subject = "Critical error!! " & strNetBIOSComputer & " failed to reboot " & Now
objMail.Textbody = "Critical error!! " & strNetBIOSComputer & " failed to reboot " & Now & vbCRLF
Set objMail = Nothing
Until next time...
As always, if there are items you would like me to talk about, please drop me a line and let me know!
Edit on September 10, 2010 - The Microsoft Collaboration Data Objects (CDO) are not installed by default on Windows Server 2008 or above. You can download them from here.