Jump to content

Event Viewer; skicka varningar via mail?


badano

Recommended Posts

Visst kan du det... så här ungefär...

'************************************************
' File:    Outlook.vbs 
' Author:  Anders Pettersson
'
' This script creates a new e-mail entry with attachement in Outlook.
'
'
'
' In no way shall the author be liable for any
' losses or damages resulting from the use of this
' program. Use AS-IS at your own risk.
'
' The code is the property of the author. You may
' use the code and modify it, as far as this header
' remains intact.
'************************************************
'
Option Explicit

Const olMailItem = 0           ' Constants for new items
Const olAppointmentItem = 1
Const olContactItem = 2
Const olTaskItem = 3
Const olJournalItem = 4
Const olNoteItem = 5
Const olPostItem = 6

Dim objOutl, objNameSpace, objMailItem, objAttachments
Dim recipient, message, subject

' define the items for the e-mail
recipient = "info@itpoolen.se"
subject = "Subject: System Log"
message = "System log från servern"

' Create Outlook object reference
Set objOutl = WScript.CreateObject("Outlook.Application")

' obtain an object reference to "Mapi" name space
Set objNameSpace = objOutl.GetNameSpace("MAPI")

' create a new mail item object
Set objMailItem = objOutl.CreateItem(olMailItem)
Set objAttachments = objMailItem.Attachments
objAttachments.Add "C:WindowsSystem32configSysEvent.Evt"

' set the mail object properties          
objMailItem.Recipients.Add recipient                ' E-mail address
objMailItem.Recipients.Add "itpoolen@gmail.com"   ' 2nd recipient

objMailItem.Subject = subject                       ' subject 
objMailItem.Body = message                          ' the body text

' now we are ready to "logon" to outlook (using Logon method) 
objNameSpace.Logon "profile", "password"
objMailItem.Send                                    ' send method
objNameSpace.Logoff                                 ' logoff

WScript.Echo "E-mail created for " & recipient      ' Post ready message

WScript.Quit()
' End

Kopiera och klistra in i ett textdokument, spara som t.ex outlook.vbs

Filen är ganska självförklarande, du får naturligtvis byta ut epostadresserna.

Detta script skickar event filen med epost...

Sedan kan du, om du vill göra ett script som kontrollerar om en fil ändrats...

--- BEGIN OF FILEMODIFICATIONCHECK.VBS ---
  Option Explicit
  Const retvalUnknown = 1
  
  ' ///////////////////////////////////////////////////////////////////////////////
  
  Function FileModificationCheck( strFile, strLogFile )
  ' Option Explicit

    Dim strPrevModDate, strCurrModDate

    FileModificationCheck = True

    strPrevModDate = Trim( ReadInfo( strLogFile ) )
    strCurrModDate = Trim( GetFileModDate( strFile ) )

    If( strCurrModDate = "" ) Then
      FileModificationCheck = retvalUnknown 
      SYSEXPLANATION        = "File does not exist" 
      SYSDATA               = ""
      Exit Function
    End If

    ' Write current date/time info, to be used in next call of FileModificationCheck
    WriteInfo strLogFile, strCurrModDate

    If( strPrevModDate = "" ) Then
      FileModificationCheck = True ' First time consider file as: not changed
      SYSEXPLANATION        = "File has not changed (first time)"
      SYSDATA               = ""
      Exit Function
    End If
  
    If( strPrevModDate = strCurrModDate ) Then
      FileModificationCheck = True ' First time consider file as: not changed
      SYSEXPLANATION        = "File has not changed"
      SYSDATA               = strCurrModDate
      Exit Function
    End If

    FileModificationCheck = False
    SYSEXPLANATION = "File has changed"

  End Function

  ' /////////////////////////////////////////////////////////////////////////////

  Function GetFileModDate( strFile )
  On Error Resume Next
    Dim fso, fsoFile

    GetFileModDate = "" 

    Set fso        = CreateObject("Scripting.FileSystemObject")
    Set fsoFile    = fso.GetFile( strFile )
    GetFileModDate = fsoFile.DateLastModified
  End Function

  ' /////////////////////////////////////////////////////////////////////////////

  Function WriteInfo( strLogFile, strInfo )
  On Error Resume Next

    Dim fso, fsoFile, fsoStream

    Set fso = CreateObject("Scripting.FileSystemObject")
    If Not fso.FileExists( strFile ) Then
      fso.CreateTextFile( strLogFile )
    End If
    Set fsoFile    = fso.GetFile( strLogFile )
    Set fsoStream  = fsoFile.OpenAsTextStream(2)	' 1=reading, 2=writing, 8=appending, 
    fsoStream.WriteLine( strInfo )
    fsoStream.Close 
  End Function

  ' /////////////////////////////////////////////////////////////////////////////

  Function ReadInfo( strLogFile )
  On Error Resume Next

    Dim fso, fsoFile, fsoStream

    ReadInfo = ""

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fsoStream = fso.OpenTextFile( strLogFile, 1, false )
    ReadInfo = fsoStream.ReadLine
    fsoStream.Close 
  End Function
--- END OF FILEMODIFICATIONCHECK.VBS ---

Kör det sista scriptet, den som söker efter en ändring, som en service

Link to comment
Share on other sites

Du kan köra script som service... och om du t.ex kör ett script som kollar event, efter förändringar. När förändring sker så aktiveras outlook-scriptet som sänder iväg ett mail till dig med en kopia av loggen.

Nästa gång som förändring sker, får du en ny kopia av loggen...

Om man gör så behövs inga extra program för det...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...