开发者

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

开发者 https://www.devze.com 2023-04-05 09:18 出处:网络
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 W

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

精彩评论

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

关注公众号