I couldn't see anything wrong, but I couldn't get it to run either, even with valid values. Question: why is the smtpserver set to localhost? Are you running your own mail server? or are you using an ISP?
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colRunningServices = objWMIService.ExecQuery("Select * from Win32_Service")
For Each objService in colRunningServices
If objService.DisplayName = "Licensing Service" And objService.State = "Stopped" Then
WScript.Echo "Licensing Service is Stopped"
Call SendMail
End If
Next
Sub SendMail()
Set CDO = CreateObject("CDO.Message")
With cdo
.From = "[email protected]"
.To = "[email protected]"
.Subject = "Service Down"
.Textbody = "Test"
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp mail server"
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
' .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "userid"
' .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
' .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Configuration.Fields.Update
.Send
End With
End Sub
If using an ISP, check with them for the smtp server name and the port to use (this information is probably on their website). If you need to use authentication, uncomment the three configuration statements and fill in the values appropriately. Yeah, I know having the userid and password in the script is a security breach, but that is whole other subject.
Good luck.