Prev: Scheduled Defrag
Next: for..in..do
From: Walser Mark on 15 Nov 2007 16:27 hello together thank you for your examples. I will try it. "urkec" <urkec(a)discussions.microsoft.com> schrieb im Newsbeitrag news:FF387254-D38B-4EA0-909B-7E5C167C9B80(a)microsoft.com... > "Walser Mark" wrote: > >> hello >> >> I search an example. >> When a event log entry, what I must do? >> I think the script look every 5 minutes into it. >> When it entry, then will send a e-mail. >> > > > This Script Center sample shows how to monitor event logs in real time: > > http://www.microsoft.com/technet/scriptcenter/scripts/logs/eventlog/lgevvb17.mspx > > This one shows how to send Email from a script: > > http://www.microsoft.com/technet/scriptcenter/scripts/message/smtpmail/default.mspx > > If you don't want your script running all the time you could set up a > permanent event consumer. You would need to create instances of three WMI > classes: __EventFilter, __EventConsumer and __FilterToConsumerBinding. > Here > is some code I took from Windows 2000 Scripting Guide: > > 'connect to WMI locally > 'can't use WScript object in Consumer.vbs > 'MsgBox will not error out but will not display > > strComputer = "." > Set objSWbemServices = GetObject("winmgmts:" _ > & "{impersonationLevel=impersonate}!\\" _ > & strComputer & "\root\cimv2") > > 'create an instance of __EventFilter class > > Set objEventFilterClass = objSWbemServices.Get("__EventFilter") > Set objEventFilter = objEventFilterClass.SpawnInstance_() > > objEventFilter.Name = "TestFilter" > objEventFilter.QueryLanguage = "WQL" > objEventFilter.Query = _ > "Select * From __InstanceModificationEvent " &_ > "Within 10 Where TargetInstance " &_ > "Isa 'Win32_Process' " > > objEventFilter.Put_ > > 'create an instance of ActiveScripteventConsumer class > > Set objConsumerClass = objSWbemServices.Get _ > ("ActiveScriptEventConsumer") > Set objConsumer = objConsumerClass.SpawnInstance_() > > objConsumer.Name = "TestConsumer" > objConsumer.ScriptFileName = "C:\Consumer.vbs" > 'it is .ScriptingEngine instead of .ScriptEngine > objConsumer.ScriptingEngine = "VBScript" > > objConsumer.Put_ > > 'need to refresh objEventFilter and objConsumer > 'before I can use their Path_ property > > objEventFilter.Refresh_ > objConsumer.Refresh_ > > 'create an instance of __FilterToConsumerBinding class > > Set objBindingClass = objSWbemServices.Get("__FilterToConsumerBinding") > Set objBindingInstance = objBindingClass.SpawnInstance_() > > 'Filter and Consumer properties are strings containing the absolute path > 'to __EventFilter and ActiveScriptEventConsumer instances just created. > ' If I want to hardcode the paths I need to use double quotes for Name > property > 'doesn't work without '\\.\' part > > objBindingInstance.Filter = objEventFilter.Path_ > objBindingInstance.Consumer = objConsumer.Path_ > > objBindingInstance.Put_() > > 'After test need to delete all three instances > > This is just test code, so you would need to adapt it. I used > ActiveScriptEventConsumer, which is derived from __EventConsumer, but one > of > the standard event consumer classes is SMTPEventConsumer, which sends an > Email message using SMTP each time an event is delivered to it. > Before I could use ActiveScriptEventConsumer, I needed to register it like > this: > > mofcomp -N:root\cimv2 %SYSTEMROOT%\system32\wbem\scrcons.mof > > I'm not sure about SMTPEventConsumer, but I think you would also need to > register it. > > http://www.microsoft.com/technet/scriptcenter/guide/sas_wmi_tjin.mspx > > -- > urkec |