Jump to content

Write to Windows Application Log


Recommended Posts

I wrote a script tonight that detects when a VNC session is established, grabs the client IP address and then gets the relevant output from "nbtstat -a <clientIP>" and puts it into a variable. The last portion of the script is to take this information and write it to the Windows Event Log (Event Viewer). I searched around but did not find anything. Does anyone know of a way to do this preferably in AutoIt? If not, are there any 3rd party utils that can be used for this?

Thanks!

Link to comment
Share on other sites

Edit: Windows XP appears to have a built in util EVENTCREATE

Here's a workaround, but I'd really like a built-in AutoIt solution:

#cs -------------------
    User-Defined function to write events to 2000/XP event log
    Information from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsmthlogevent.asp
    
    LIMITATIONS
     1)  You can only write to the "Applications" log
     2)  The source will always appear as "WSH"
     3)  The event ID can only be one of the following:
            0    SUCCESS
            1    ERROR
            2    WARNING
            4    INFORMATION
            8    AUDIT_SUCCESS
            16   AUDIT_FAILURE
    4)  The category and type will both be "None"
#ce -------------------

_LogEvent("This is a sample event messsage!")
_LogEvent("This is another message from AutoIt!", 0)
Exit

Func _LogEvent($message, $ID = 4)
; If $ID is an invalid number, then use 4 as default value
    If $ID > 16 Or $ID < 0 Or BitAND($ID,-$ID) <> $ID then $ID = 4
; It might be bad if message contains double quotes, so replace them with single quotes
    $message = StringReplace($message, '"', "'")
    
    Local $tempFile = @TempDir & "\AutoItLogEvent.vbs"
    Local $handle = FileOpen($tempFile, 2);overwrite
    FileWriteLine($handle, 'Set WshShell = WScript.CreateObject("WScript.Shell")')
    FileWriteLine($handle, 'WshShell.LogEvent ' & $ID & ', "' & $message & '"')
    If $handle <> -1 Then
        FileClose($handle)
        RunWait("WScript.exe " & $tempFile)
        FileDelete($tempFile)
    EndIf
EndFunc
Edited by CyberSlug
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...