Jump to content
Sign in to follow this  
sublimnl

Write to Windows Application Log

Recommended Posts

sublimnl

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!

Share this post


Link to post
Share on other sites
CyberSlug

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!

Share this post


Link to post
Share on other sites
this-is-me

Am I remembering incorrectly, or did Larry also code something like this into Au3Xtra.dll?


Who else would I be?

Share this post


Link to post
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
Sign in to follow this  

×