开发者

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 Scri开发者_如何学JAVApting Host (as a .js file). I was wondering if it's possible to write into the Windows Event Log from it?


You can log the event directly after by using WscriptShell object itself:

var oWSS = new ActiveXObject("WScript.Shell"); 
oWSS.LogEvent(1,"this is error"); 
oWSS.LogEvent(2,"this is warning"); 
oWSS.LogEvent(4,"this is Info");


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('"', '""') + '"')
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜