mercoledì 11 febbraio 2009

Windows: spedire mail da eventtriggers

Script creato da Shane Rudy per spedire mail da eventtriggers.
(non ho avuto ancora modo di testarlo)
N.B.: utilzzare il parametro /ru

Trovate altre discussioni su questo argomento QUI

const cdoSendUsingPort = 2
const cdoAnonymous = 0
set msg = CreateObject("CDO.Message")
set config = CreateObject("CDO.Configuration")
set msg.Configuration = config
txt = ""

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colLoggedEvents = objWMIService.ExecQuery _
("Select * from Win32_NTLogEvent Where Logfile = 'Application' and " _
& "Type = 'error'")
For Each objEvent in colLoggedEvents
txt = txt & objEvent.TimeWritten & vbCRLF & objEvent.ComputerName & vbCRLF & objEvent.Type & vbCRLF & _
objEvent.EventCode & vbCRLF & objEvent.Message & "http://eventid.net/display.asp?eventid" & _
vbCRLF & objEvent.User & vbCRLF & vbCRLF

Next

if txt <> "" then

txt = "The Following Application Errors Have Occurred on COMPUTERNAME: " & vbcrlf & vbCRLF & txt

else
Wscript.Quit(0)
end if

With msg
.to = """WhoEver""whoever@wherever.com "
.from = """WhoEver"" "
.subject = "Application Errors on ComputerName"
.textbody = txt
End with

prefix = "http://schemas.microsoft.com/cdo/configuration/"

With config.fields
.item(prefix & "sendusing") = cdoSendUsingPort
.item(prefix & "smtpserver") = "SMTPServer"
.item(prefix & "smtpauthenticate") = cdoAnonymous
.update
End With

on error resume next
msg.send
send_error = error.number
on error goto 0

if send_error <> 0 then
wscript.echo "Error Sending Your Message"
wscript.quit 0


end if

Nessun commento: