Search code examples
javascriptevent-log

Can I write into Windows Event Log from a Windows Scripting Language like JScript?


I have a small JScript code that needs to output its error messages. It is running from a Windows Scripting Host (as a .js file). I was wondering if it's possible to write into the Windows Event Log from it?


Solution

  • This blog does it this way:

    function Log(message) {
        var shell = new ActiveXObject("WScript.Shell")
        shell.Exec('eventcreate /id 1 /l [LOG] /SO [SOURCE] /T ERROR /D "' + String(message).replace('"', '""') + '"')
    }