Hello. I have a task to familiarize with examples of scripts WMI and to launch them. The problems are as follows:
- On the site with an example of an explanation in general, no. I tried to figure it out, but it seems to me that for the first time, and indeed the first example in general, it is a bit difficult to understand something without sensible explanations. Something tried to understand but alas ...
- I decided to at least see how the code from the example will work (transfer records from the System event log on the local computer to the EventLog.mdb database with the ComputerName, EventType, EventCode, Message and TimeWritten fields; after the end of the transfer, the System event log is cleared). I get an error:
And they said that the scripts will be executed in PowerShell without any problems. Or is it because of the lack of a database?
Option Explicit // это начало подключения к WMI Dim cn, rs, oLocator, oSvc, oColEvents, oColEventLog, Item, oLogFile // создание переменных оболочек объектов? Set cn = CreateObject("ADODB.Connection") // создаем объект используя оболочку cn (как в Java)? cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data // видимо делаем преобразовываем в строчку что-то???? Source=C:\EventLog.mdb" // указыаем источких для обработки данных cn.Open // не понятно что открываем Set rs = CreateObject("ADODB.Recordset") rs.CursorType = 3 rs.LockType = 3 rs.Open "Events", cn Set oLocator = CreateObject("wbemScripting.Swbemlocator") Set oSvc = oLocator.ConnectServer() Set oColEvents = oSvc.ExecQuery _ ("Select * from Win32_NTLogEvent WHERE Logfile = 'System'") For Each Item In oColEvents rs.AddNew rs("ComputerName") = Item.ComputerName rs("EventType") = Item.Type rs("EventCode") = Item.EventCode rs("Message") = Item.Message rs("TimeWritten") = Item.TimeWritten rs.Update Next Set oColEventLog = oSvc.ExecQuery _ ("Select * from Win32_NTEventLogFile WHERE LogFileName = 'System'") For Each oLogFile In oColEventLog oLogFile.ClearEventLog Next WScript.Echo "Done" In general, I ask for help with an explanation.