Jump to content

Store errors/log data into the windows event viewer


Recommended Posts

I searched but didnt really come up with anything.

Are there any UDFs out there that allow me to create a category for compiled script in the Windows Event Viewer in the event that my scripts set and error levels or var$ data maybe. Kinda like System or Applications Logs now Internet Explorer has its own category. I would like to have my own.

Thanks,

GoogleDude

Link to comment
Share on other sites

This is probably not what you want but you could do something like this:

Func LogEvent($strLocation, $strType, $IntID, $strSource, $strEventMessage)
    Local $CheckEventViewer = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\YOURENTRY","EVENTVIEWERNAME")
    
    If Not $CheckEventViewer Then
        RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\EventLog\YOURENTRY","EVENTVIEWERNAME","REG_DWORD","1")
    EndIf
    
    Sleep(200)
    
    RunWait("EVENTCREATE /T " & $strType & " /ID " & $IntID & " /L " & $strLocation & " /SO " & $strSource & " /D " & CHR(34) & $strEventMessage & CHR(34),@SystemDir,@SW_HIDE)
EndFunc

The above function will check to make sure that event viewer entry is there and if it is it will log everything you specify within that event viewer log.

[sub]Quantum mechanics: The dreams stuff is made of[/sub]

Link to comment
Share on other sites

  • 7 months later...

DarkMatter, could you please explain these variables? $strLocation, $strType, $IntID, $strSource, $strEventMessage

This is probably not what you want but you could do something like this:

Func LogEvent($strLocation, $strType, $IntID, $strSource, $strEventMessage)
    Local $CheckEventViewer = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\YOURENTRY","EVENTVIEWERNAME")
    
    If Not $CheckEventViewer Then
        RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\EventLog\YOURENTRY","EVENTVIEWERNAME","REG_DWORD","1")
    EndIf
    
    Sleep(200)
    
    RunWait("EVENTCREATE /T " & $strType & " /ID " & $IntID & " /L " & $strLocation & " /SO " & $strSource & " /D " & CHR(34) & $strEventMessage & CHR(34),@SystemDir,@SW_HIDE)
EndFunc

The above function will check to make sure that event viewer entry is there and if it is it will log everything you specify within that event viewer log.

Edited by ghetek
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...