Код:
![Выделить весь код](images/misc/selectcode.png)
Option Explicit
Const cdoSendUsingPort = 2
Const cdoBasic = 1
Const strSchema = "http://schemas.microsoft.com/cdo/configuration/"
Dim arrProcesses
Dim strComputer
Dim objSWbemLocator
Dim objSWbemServicesEx
Dim collSWbemObjectSet
Dim objSWbemObjectEx
Dim elem
Dim objFSO
Dim lngProcessID
arrProcesses = Array("C:\WINDOWS\system32\notepad.exe", "C:\WINDOWS\system32\calc.exe", "C:\WINDOWS\system32\mspaint.exe")
strComputer = "."
Set objSWbemLocator = WScript.CreateObject("WbemScripting.SWbemLocator")
Set objSWbemServicesEx = objSWbemLocator.ConnectServer(strComputer, "root\cimv2")
Set collSWbemObjectSet = objSWbemServicesEx.ExecNotificationQuery("SELECT * From __InstanceDeletionEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_Process'")
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Do
Set objSWbemObjectEx = collSWbemObjectSet.NextEvent.TargetInstance
For Each elem In arrProcesses
If objSWbemObjectEx.Name = objFSO.GetFileName(elem) Then
With WScript.CreateObject("CDO.Message")
.From = "account@mail.ru"
.To = "account@yandex.ru"
.Subject = "Process [" & objFSO.GetFileName(elem) & "] closed."
If objSWbemServicesEx.Get("Win32_Process").Create(elem, objFSO.GetParentFolderName(elem), Nothing, lngProcessID) = 0 Then
.Textbody = Now() & vbTab & "Process [" & elem & "] successfully started."
Else
.Textbody = Now() & vbTab & "Can't create process [" & elem & "]."
End If
With .Configuration.Fields
.Item(strSchema & "smtpserver") = "smtp.mail.ru"
.Item(strSchema & "sendusing") = cdoSendUsingPort
.Item(strSchema & "smtpserverport") = 25
.Item(strSchema & "smtpauthenticate") = cdoBasic
.Item(strSchema & "sendusername") = "account@mail.ru"
.Item(strSchema & "sendpassword") = "password"
.Update
End With
.Send
End With
Exit For
End If
Next
Loop
Set objFSO = Nothing
Set collSWbemObjectSet = Nothing
Set objSWbemServicesEx = Nothing
Set objSWbemLocator = Nothing
WScript.Quit 0