hey I need help I'm trying to get this script to listen for a specific user logging onto a large list of machines pulled from a text file and then email me. How should I break out of the Do While loop to actually send the email?
thanx
thanx
Code:
On Error Resume Next
strEmail = InPutBox ("Enter email address to send alerts to. Seperate multiple address' with a semicolon ;")
'strComputer = InPutBox ("Enter Server Name:")
Set Fso = CreateObject("Scripting.FileSystemObject")
strFile = InPutBox ("Please enter the name of the text file that has the list of the PC you want to monitor:")
Set InputFile = fso.OpenTextFile(strFile)
Do While Not (InputFile.atEndOfStream)
strComputer = InputFile.ReadLine
'strEvent = InPutBox ("Enter Username to monitor:")
Set objWMIService = GetObject("winmgmts:{(Security)}\\" & _
strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("Select * from __InstanceCreationEvent Where " _
& "TargetInstance ISA 'Win32_NTLogEvent' " _
& "and TargetInstance.user = 'domain\\user.name' "_
& "and TargetInstance.EventCode = '528' ")
Do
Set objLatestEvent = colMonitoredEvents.NextEvent
SendMessage objLatestEvent.TargetInstance.Message
Loop
Sub SendMessage (sText)
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "somebody@somewhere.com"
objEmail.To = strEmail
objEmail.Subject = "user.name has logged on to " & strComputer
objEmail.Textbody = objLatestEvent.TargetInstance.User & vbCrLf & objLatestEvent.TargetInstance.Message
'objEmail.AddAttachment ""
objEmail.Configuration.Fields.Item _
("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing")[/URL] = 2
objEmail.Configuration.Fields.Item _
("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver")[/URL] = _
"echosmtp1.echostar.com"
objEmail.Configuration.Fields.Item _
("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserverport")[/URL] = 25
objEmail.Configuration.Fields.Update
objEmail.Send
End Sub