熱點推薦:
您现在的位置: 電腦知識網 >> 操作系統 >> Windows系統管理 >> 正文

windows事件日志寫入sqlserver

2022-06-13   來源: Windows系統管理 

  Set objConn = CreateObject(ADODBConnection)

  Set objRS = CreateObject(ADODBRecordset)

  objConnOpen Provider=SQLOLEDB;Password=****;Persist Security Info=True;User ID=zhang;Initial Catalog=IPOPJ;Data Source=SV\SQLEXPRESS

  objRSCursorLocation =

  objRSOpen SELECT * FROM EventTable objConn

  Set dtmStartDate = CreateObject(WbemScriptingSWbemDateTime)

  Set dtmEndDate = CreateObject(WbemScriptingSWbemDateTime)

  DateToCheck = Date

  dtmEndDateSetVarDate Date True

  dtmStartDateSetVarDate DateToCheck True

  strComputer =

  Set objWMIService = GetObject(winmgmts: _

  & {impersonationLevel=impersonate}!\\ & strComputer & \root\cimv)

  Set colEvents = objWMIServiceExecQuery _

  (Select * from Win_NTLogEvent Where Logfile = Security _

  & And TimeWritten >=   & dtmStartDate & and TimeWritten < & dtmEndDate & )

  For each objEvent in colEvents

  objRSAddNew

  objRS(Category) = objEventCategory

  objRS(ComputerName) = objEventComputerName

  objRS(EventCode) = objEventEventCode

  objRS(Message) = objEventMessage

  objRS(RecordNumber) = objEventRecordNumber

  objRS(SourceName) = objEventSourceName

  objRS(TimeWritten) = objEventTimeWritten

  objRS(Type) = objEventType

  objRS(UserName) = objEventUser

  objRSUpdate

  Next

  objRSClose

  objConnClose


From:http://tw.wingwit.com/Article/os/xtgl/201311/8745.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.