Write to Windows event log: Difference between revisions

Content added Content deleted
mNo edit summary
m (syntax highlighting fixup automation)
Line 8: Line 8:
{{trans|C}}
{{trans|C}}


<lang 11l>:start:
<syntaxhighlight lang="11l">:start:
I :argv.len != 5
I :argv.len != 5
print(‘Usage : #. < Followed by level, id, source string and description>’.format(:argv[0]))
print(‘Usage : #. < Followed by level, id, source string and description>’.format(:argv[0]))
E
E
os:(‘EventCreate /t #. /id #. /l APPLICATION /so #. /d "#."’.format(:argv[1], :argv[2], :argv[3], :argv[4]))</lang>
os:(‘EventCreate /t #. /id #. /l APPLICATION /so #. /d "#."’.format(:argv[1], :argv[2], :argv[3], :argv[4]))</syntaxhighlight>


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
<lang autohotkey>; By ABCza, http://www.autohotkey.com/board/topic/76170-function-send-windows-log-events/
<syntaxhighlight lang="autohotkey">; By ABCza, http://www.autohotkey.com/board/topic/76170-function-send-windows-log-events/
h := RegisterForEvents("AutoHotkey")
h := RegisterForEvents("AutoHotkey")
SendWinLogEvent(h, "Test Message")
SendWinLogEvent(h, "Test Message")
Line 204: Line 204:
; Return the number of characters copied.
; Return the number of characters copied.
return char_count
return char_count
}</lang>
}</syntaxhighlight>


=={{header|AWK}}==
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f WRITE_TO_WINDOWS_EVENT_LOG.AWK
# syntax: GAWK -f WRITE_TO_WINDOWS_EVENT_LOG.AWK
BEGIN {
BEGIN {
Line 226: Line 226:
}
}
function error(message) { printf("error: %s\n",message) ; errors++ }
function error(message) { printf("error: %s\n",message) ; errors++ }
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 234: Line 234:
=={{header|Batch File}}==
=={{header|Batch File}}==
The "EventCreate" command does the task.
The "EventCreate" command does the task.
<lang dos>@echo off
<syntaxhighlight lang="dos">@echo off
EventCreate /t ERROR /id 123 /l SYSTEM /so "A Batch File" /d "This is found in system log."
EventCreate /t ERROR /id 123 /l SYSTEM /so "A Batch File" /d "This is found in system log."
EventCreate /t WARNING /id 456 /l APPLICATION /so BlaBla /d "This is found in apps log"</lang>
EventCreate /t WARNING /id 456 /l APPLICATION /so BlaBla /d "This is found in apps log"</syntaxhighlight>
{{Out}}
{{Out}}
<pre>>EventLog.BAT
<pre>>EventLog.BAT
Line 246: Line 246:
></pre>
></pre>
If you do not want the command to display its result or errors...
If you do not want the command to display its result or errors...
<lang dos>@echo off
<syntaxhighlight lang="dos">@echo off
EventCreate /t ERROR /id 123 /l SYSTEM /so "A Batch File" /d "This is found in system log." >NUL 2>&1
EventCreate /t ERROR /id 123 /l SYSTEM /so "A Batch File" /d "This is found in system log." >NUL 2>&1
EventCreate /t WARNING /id 456 /l APPLICATION /so BlaBla /d "This is found in apps log" >NUL 2>&1
EventCreate /t WARNING /id 456 /l APPLICATION /so BlaBla /d "This is found in apps log" >NUL 2>&1
::That ">NUL 2>&1" trick actually works in any command!</lang>
::That ">NUL 2>&1" trick actually works in any command!</syntaxhighlight>


'''NOTE:''' This will (...or might) not work if you do not have administrator privileges.
'''NOTE:''' This will (...or might) not work if you do not have administrator privileges.
Line 256: Line 256:
{{works with|BBC BASIC for Windows}}
{{works with|BBC BASIC for Windows}}
Writes to the Application Log:
Writes to the Application Log:
<lang bbcbasic> INSTALL @lib$+"COMLIB"
<syntaxhighlight lang="bbcbasic"> INSTALL @lib$+"COMLIB"
PROC_cominitlcid(1033)
PROC_cominitlcid(1033)
Line 263: Line 263:
PROC_releaseobject(WshShell%)
PROC_releaseobject(WshShell%)
PROC_comexit</lang>
PROC_comexit</syntaxhighlight>


=={{header|C}}==
=={{header|C}}==
The following is a wrapper on the EventCreate utility provided in Windows. Note that to use this wrapper, the code must be executed from a console/IDE running as Administrator. The utility itself does extensive error-checking and validation, so apart from the check that 5 arguments have been supplied, no other validations or checks are performed.
The following is a wrapper on the EventCreate utility provided in Windows. Note that to use this wrapper, the code must be executed from a console/IDE running as Administrator. The utility itself does extensive error-checking and validation, so apart from the check that 5 arguments have been supplied, no other validations or checks are performed.
<syntaxhighlight lang="c">
<lang C>
#include<stdlib.h>
#include<stdlib.h>
#include<stdio.h>
#include<stdio.h>
Line 284: Line 284:
return 0;
return 0;
}
}
</syntaxhighlight>
</lang>
Invocation and output on console :
Invocation and output on console :
<pre>
<pre>
Line 295: Line 295:
=={{header|C sharp}}==
=={{header|C sharp}}==
In Windows Vista and later or Windows Server 2003, you must have administrative privileges to execute this code.
In Windows Vista and later or Windows Server 2003, you must have administrative privileges to execute this code.
<lang csharp>using System.Diagnostics;
<syntaxhighlight lang="csharp">using System.Diagnostics;


namespace RC
namespace RC
Line 314: Line 314:
}
}
}
}
}</lang>
}</syntaxhighlight>


=={{header|C++}}==
=={{header|C++}}==
{{trans|C}}
{{trans|C}}
<lang cpp>#include <iostream>
<syntaxhighlight lang="cpp">#include <iostream>
#include <sstream>
#include <sstream>


Line 338: Line 338:


return 0;
return 0;
}</lang>
}</syntaxhighlight>


=={{header|Clojure}}==
=={{header|Clojure}}==
<lang clojure>(use 'clojure.java.shell)
<syntaxhighlight lang="clojure">(use 'clojure.java.shell)
(sh "eventcreate" "/T" "INFORMATION" "/ID" "123" "/D" "Rosetta Code example")</lang>
(sh "eventcreate" "/T" "INFORMATION" "/ID" "123" "/D" "Rosetta Code example")</syntaxhighlight>


=={{header|D}}==
=={{header|D}}==
{{trans|Kotlin}}
{{trans|Kotlin}}
<lang D>import std.process;
<syntaxhighlight lang="d">import std.process;
import std.stdio;
import std.stdio;


Line 357: Line 357:
writeln("Failed to execute command, status=", cmd.status);
writeln("Failed to execute command, status=", cmd.status);
}
}
}</lang>
}</syntaxhighlight>


=={{header|Delphi}}==
=={{header|Delphi}}==
<lang Delphi>program WriteToEventLog;
<syntaxhighlight lang="delphi">program WriteToEventLog;


{$APPTYPE CONSOLE}
{$APPTYPE CONSOLE}
Line 385: Line 385:
begin
begin
WriteLog('Message to log.');
WriteLog('Message to log.');
end.</lang>
end.</syntaxhighlight>


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
<p>Bare bone writing to the Application Eventlog giving no event-ID and using the default event type (information.)</p>
<p>Bare bone writing to the Application Eventlog giving no event-ID and using the default event type (information.)</p>
<lang fsharp>use log = new System.Diagnostics.EventLog()
<syntaxhighlight lang="fsharp">use log = new System.Diagnostics.EventLog()
log.Source <- "Sample Application"
log.Source <- "Sample Application"
log.WriteEntry("Entered something in the Application Eventlog!")</lang>
log.WriteEntry("Entered something in the Application Eventlog!")</syntaxhighlight>


=={{header|Go}}==
=={{header|Go}}==
This works on Windows 10 with administrative privileges.
This works on Windows 10 with administrative privileges.
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 411: Line 411:
fmt.Println(err)
fmt.Println(err)
}
}
}</lang>
}</syntaxhighlight>


=={{header|Java}}==
=={{header|Java}}==
<lang java>import java.io.BufferedReader;
<syntaxhighlight lang="java">import java.io.BufferedReader;
import java.io.IOException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStream;
Line 442: Line 442:
}
}
}
}
}</lang>
}</syntaxhighlight>


=={{header|Julia}}==
=={{header|Julia}}==
Run as an administrator.
Run as an administrator.
<lang julia>
<syntaxhighlight lang="julia">
cmd = "eventcreate /T INFORMATION /ID 123 /D \"Rosetta Code Write to Windows event log task example\""
cmd = "eventcreate /T INFORMATION /ID 123 /D \"Rosetta Code Write to Windows event log task example\""
Base.run(`$cmd`)
Base.run(`$cmd`)
</syntaxhighlight>
</lang>


=={{header|Kotlin}}==
=={{header|Kotlin}}==
The following works on Windows 10 with administrative privileges:
The following works on Windows 10 with administrative privileges:
<lang scala>// version 1.1.4-3
<syntaxhighlight lang="scala">// version 1.1.4-3


fun main(args: Array<String>) {
fun main(args: Array<String>) {
Line 464: Line 464:


Runtime.getRuntime().exec(command)
Runtime.getRuntime().exec(command)
}</lang>
}</syntaxhighlight>


=={{header|Lingo}}==
=={{header|Lingo}}==
{{libheader|Shell xtra}}
{{libheader|Shell xtra}}
<lang Lingo>shell = xtra("Shell").new()
<syntaxhighlight lang="lingo">shell = xtra("Shell").new()
props = [:]
props = [:]
props["operation"] = "runas"
props["operation"] = "runas"
props["parameters"] = "/t INFORMATION /id 123 /l APPLICATION /so Lingo /d "&QUOTE&"Rosetta Code Example"&QUOTE
props["parameters"] = "/t INFORMATION /id 123 /l APPLICATION /so Lingo /d "&QUOTE&"Rosetta Code Example"&QUOTE
shell.shell_exec("EventCreate", props)</lang>
shell.shell_exec("EventCreate", props)</syntaxhighlight>


=={{header|Perl}}==
=={{header|Perl}}==
Line 478: Line 478:
The Win32::EventLog module has the Report method to write in the EventLog
The Win32::EventLog module has the Report method to write in the EventLog


<lang perl>
<syntaxhighlight lang="perl">
use strict;
use strict;
use warnings;
use warnings;
Line 495: Line 495:
};
};
$handle->Report($event);
$handle->Report($event);
</syntaxhighlight>
</lang>


=={{header|Phix}}==
=={{header|Phix}}==
The first two lines are of course entirely optional, but could help prevent someone/a newbie from wasting their time trying to achieve the impossible.
The first two lines are of course entirely optional, but could help prevent someone/a newbie from wasting their time trying to achieve the impossible.
<!--<lang Phix>(notonline)-->
<!--<syntaxhighlight lang="phix">(notonline)-->
<span style="color: #7060A8;">requires</span><span style="color: #0000FF;">(</span><span style="color: #004600;">WINDOWS</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- (as in this will not work on Linux or p2js, duh)</span>
<span style="color: #7060A8;">requires</span><span style="color: #0000FF;">(</span><span style="color: #004600;">WINDOWS</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- (as in this will not work on Linux or p2js, duh)</span>
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (as above, also prevent pointless attempts to transpile)</span>
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (as above, also prevent pointless attempts to transpile)</span>
<span style="color: #7060A8;">system</span><span style="color: #0000FF;">(</span><span style="color: #008000;">`eventcreate /T INFORMATION /ID 123 /D "Rosetta Code Write to Windows event log task example"`</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">system</span><span style="color: #0000FF;">(</span><span style="color: #008000;">`eventcreate /T INFORMATION /ID 123 /D "Rosetta Code Write to Windows event log task example"`</span><span style="color: #0000FF;">)</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}} (when running as administrator)
{{out}} (when running as administrator)
<pre>
<pre>
Line 511: Line 511:
=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
PicoLisp doesn't run on Windows. In case of Linux, the equivalent of the event log is the syslog. It can be written with '[http://software-lab.de/doc/refN.html#native native]' C functions, or simply with the 'logger' utility:
PicoLisp doesn't run on Windows. In case of Linux, the equivalent of the event log is the syslog. It can be written with '[http://software-lab.de/doc/refN.html#native native]' C functions, or simply with the 'logger' utility:
<lang PicoLisp>: (call 'logger "This is a test")
<syntaxhighlight lang="picolisp">: (call 'logger "This is a test")
-> T
-> T


: (call 'logger "This" 'is "another" 'test)
: (call 'logger "This" 'is "another" 'test)
-> T</lang>
-> T</syntaxhighlight>


=={{header|PowerShell}}==
=={{header|PowerShell}}==
<lang powershell># Create Event Log object
<syntaxhighlight lang="powershell"># Create Event Log object
$EventLog=new-object System.Diagnostics.EventLog("Application")
$EventLog=new-object System.Diagnostics.EventLog("Application")
#Declare Event Source; must be 'registered' with Windows
#Declare Event Source; must be 'registered' with Windows
Line 530: Line 530:


# Write the event in the format "Event test",EventType,EventID
# Write the event in the format "Event test",EventType,EventID
$EventLog.WriteEntry("My Test Event",$infoevent,70)</lang>
$EventLog.WriteEntry("My Test Event",$infoevent,70)</syntaxhighlight>
''Note1:'' Thanks to PoSH Fan for posting information that got me started on this at [http://winpowershell.blogspot.com/2006/07/writing-windows-events-using.html Windows PowerShell Blog]
''Note1:'' Thanks to PoSH Fan for posting information that got me started on this at [http://winpowershell.blogspot.com/2006/07/writing-windows-events-using.html Windows PowerShell Blog]
<br>
<br>
Line 536: Line 536:


===Source and event log existing===
===Source and event log existing===
<lang powershell>
<syntaxhighlight lang="powershell">
$MessageFreeLula = 'Global unions and union leaders from more than 50 countries came together ' +
$MessageFreeLula = 'Global unions and union leaders from more than 50 countries came together ' +
'in Geneva today to stand in solidarity with former Brazilian President Lula, calling for ' +
'in Geneva today to stand in solidarity with former Brazilian President Lula, calling for ' +
Line 542: Line 542:
Write-EventLog -LogName 'System' -Source 'Eventlog' -Message $MessageFreeLula -EventId 13 -EntryType 'Information'
Write-EventLog -LogName 'System' -Source 'Eventlog' -Message $MessageFreeLula -EventId 13 -EntryType 'Information'
'SUCCESS: The Lula Livre message (#FreeLula) has been recorded in the system log event.'
'SUCCESS: The Lula Livre message (#FreeLula) has been recorded in the system log event.'
</syntaxhighlight>
</lang>
{{out|output}}
{{out|output}}
<pre>
<pre>
Line 548: Line 548:
</pre>
</pre>
===New event log===
===New event log===
<lang powershell>
<syntaxhighlight lang="powershell">
$MessageFreeLula = 'Global unions and union leaders from more than 50 countries came together ' +
$MessageFreeLula = 'Global unions and union leaders from more than 50 countries came together ' +
'in Geneva today to stand in solidarity with former Brazilian President Lula, calling for ' +
'in Geneva today to stand in solidarity with former Brazilian President Lula, calling for ' +
Line 556: Line 556:
Write-EventLog -LogName 'Free Lula!' -Source '#FreeLula' -Message $MessageFreeLula -EventId 13 -EntryType 'Information'
Write-EventLog -LogName 'Free Lula!' -Source '#FreeLula' -Message $MessageFreeLula -EventId 13 -EntryType 'Information'
'SUCCESS: The Lula Livre message (#FreeLula) has been recorded in the "Free Lula!" log event.'
'SUCCESS: The Lula Livre message (#FreeLula) has been recorded in the "Free Lula!" log event.'
</syntaxhighlight>
</lang>
{{out|output}}
{{out|output}}
<pre>
<pre>
Line 563: Line 563:


=={{header|PureBasic}}==
=={{header|PureBasic}}==
<lang PureBasic>Procedure WriteToLog(Event_App$,EventMessage$,EvenetType,Computer$)
<syntaxhighlight lang="purebasic">Procedure WriteToLog(Event_App$,EventMessage$,EvenetType,Computer$)


Protected wNumStrings.w, lpString=@EventMessage$, lReturnX, CMessageTyp, lparray
Protected wNumStrings.w, lpString=@EventMessage$, lReturnX, CMessageTyp, lparray
Line 576: Line 576:


ProcedureReturn Result
ProcedureReturn Result
EndProcedure</lang>
EndProcedure</syntaxhighlight>


=={{header|Python}}==
=={{header|Python}}==
Line 582: Line 582:
{{libheader|PyWin32}}
{{libheader|PyWin32}}


<lang Python>import win32api
<syntaxhighlight lang="python">import win32api
import win32con
import win32con
import win32evtlog
import win32evtlog
Line 600: Line 600:


win32evtlogutil.ReportEvent(applicationName, eventID, eventCategory=category,
win32evtlogutil.ReportEvent(applicationName, eventID, eventCategory=category,
eventType=myType, strings=descr, data=data, sid=my_sid)</lang>
eventType=myType, strings=descr, data=data, sid=my_sid)</syntaxhighlight>


=={{header|Racket}}==
=={{header|Racket}}==
Racket's logging facility creates windows events when running on Windows.
Racket's logging facility creates windows events when running on Windows.


<syntaxhighlight lang="racket">
<lang Racket>
#lang racket
#lang racket
(log-warning "Warning: nothing went wrong.")
(log-warning "Warning: nothing went wrong.")
</syntaxhighlight>
</lang>


=={{header|Raku}}==
=={{header|Raku}}==
Line 617: Line 617:
(Same caveats as the others, needs to be run as administrator or with elevated privileges under Windows.)
(Same caveats as the others, needs to be run as administrator or with elevated privileges under Windows.)


<lang perl6>given $*DISTRO {
<syntaxhighlight lang="raku" line>given $*DISTRO {
when .is-win {
when .is-win {
my $cmd = "eventcreate /T INFORMATION /ID 123 /D \"Bla de bla bla bla\"";
my $cmd = "eventcreate /T INFORMATION /ID 123 /D \"Bla de bla bla bla\"";
Line 627: Line 627:
$logger.info("[$*PROGRAM-NAME pid=$*PID user=$*USER] Just thought you might like to know.");
$logger.info("[$*PROGRAM-NAME pid=$*PID user=$*USER] Just thought you might like to know.");
}
}
}</lang>
}</syntaxhighlight>


=={{header|REXX}}==
=={{header|REXX}}==
Line 633: Line 633:


===annotated===
===annotated===
<lang rexx>/*REXX program writes a "record" (event) to the (Microsoft) Windows event log. */
<syntaxhighlight lang="rexx">/*REXX program writes a "record" (event) to the (Microsoft) Windows event log. */


eCMD = 'EVENTCREATE' /*name of the command that'll be used. */
eCMD = 'EVENTCREATE' /*name of the command that'll be used. */
Line 645: Line 645:
eCMD '/T' type "/ID" id '/L' logName "/SO" source '/D' desc
eCMD '/T' type "/ID" id '/L' logName "/SO" source '/D' desc


/*stick a fork in it, we're all done. */</lang>
/*stick a fork in it, we're all done. */</syntaxhighlight>
{{out|output}}
{{out|output}}
<pre>
<pre>
Line 652: Line 652:


===bare bones===
===bare bones===
<lang rexx>/*REXX program writes a "record" (event) to the (Microsoft) Windows event log. */
<syntaxhighlight lang="rexx">/*REXX program writes a "record" (event) to the (Microsoft) Windows event log. */
/* [↓] cmd options have extra spacing.*/
/* [↓] cmd options have extra spacing.*/


Line 658: Line 658:
'/D "attempting to add an entry for a Rosetta Code demonstration."'
'/D "attempting to add an entry for a Rosetta Code demonstration."'


/*stick a fork in it, we're all done. */</lang>
/*stick a fork in it, we're all done. */</syntaxhighlight>
{{out|output|text=&nbsp; is identical to the 1<sup>st</sup> REXX version.}} <br><br>
{{out|output|text=&nbsp; is identical to the 1<sup>st</sup> REXX version.}} <br><br>


=={{header|Ruby}}==
=={{header|Ruby}}==
{{libheader|win32-utils}}
{{libheader|win32-utils}}
<lang ruby>require 'win32/eventlog'
<syntaxhighlight lang="ruby">require 'win32/eventlog'
logger = Win32::EventLog.new
logger = Win32::EventLog.new
logger.report_event(:event_type => Win32::EventLog::INFO, :data => "a test event log entry")</lang>
logger.report_event(:event_type => Win32::EventLog::INFO, :data => "a test event log entry")</syntaxhighlight>


Instructions on setting up an Event Source is [http://rubyforge.org/docman/view.php/85/1734/mc_tutorial.html here]
Instructions on setting up an Event Source is [http://rubyforge.org/docman/view.php/85/1734/mc_tutorial.html here]


=={{header|Rust}}==
=={{header|Rust}}==
<lang rust>
<syntaxhighlight lang="rust">
#[cfg(windows)]
#[cfg(windows)]
mod bindings {
mod bindings {
Line 749: Line 749:
println!("Not implemented");
println!("Not implemented");
}
}
</syntaxhighlight>
</lang>
add this to the build.rs:
add this to the build.rs:
<lang rust>
<syntaxhighlight lang="rust">
fn main() {
fn main() {
#[cfg(windows)]
#[cfg(windows)]
Line 759: Line 759:
}
}
}
}
</syntaxhighlight>
</lang>
And this to cargo.toml:
And this to cargo.toml:
<lang rust>
<syntaxhighlight lang="rust">
[target.'cfg(windows)'.dependencies]
[target.'cfg(windows)'.dependencies]
windows = "0.7.0"
windows = "0.7.0"
Line 767: Line 767:
[target.'cfg(windows)'.build-dependencies]
[target.'cfg(windows)'.build-dependencies]
windows = "0.7.0"
windows = "0.7.0"
</syntaxhighlight>
</lang>


=={{header|Scala}}==
=={{header|Scala}}==
The following works on Windows 10 with elevated (administrative) permission:
The following works on Windows 10 with elevated (administrative) permission:
<lang Scala>object RegisterWinLogEvent extends App {
<syntaxhighlight lang="scala">object RegisterWinLogEvent extends App {


import sys.process._
import sys.process._
Line 781: Line 781:
println(s"\nSuccessfully completed without errors. [total ${scala.compat.Platform.currentTime - executionStart} ms]")
println(s"\nSuccessfully completed without errors. [total ${scala.compat.Platform.currentTime - executionStart} ms]")


}</lang>
}</syntaxhighlight>


=={{header|Standard ML}}==
=={{header|Standard ML}}==
From bsd/linux/unix to log
From bsd/linux/unix to log
<syntaxhighlight lang="standard ml">
<lang Standard ML>
OS.Process.system "logger \"Log event\" " ;
OS.Process.system "logger \"Log event\" " ;
</syntaxhighlight>
</lang>
From MS Windows to MS Windows, taken from C:
From MS Windows to MS Windows, taken from C:
<syntaxhighlight lang="standard ml">
<lang Standard ML>
OS.Process.system "EventCreate /t WARNING /id 458 /l APPLICATION /so SomeSource /d \"Settastring\"" ;
OS.Process.system "EventCreate /t WARNING /id 458 /l APPLICATION /so SomeSource /d \"Settastring\"" ;
</syntaxhighlight>
</lang>


=={{header|Tcl}}==
=={{header|Tcl}}==
{{libheader|TWAPI}}
{{libheader|TWAPI}}
<lang tcl>package require twapi
<syntaxhighlight lang="tcl">package require twapi


# This command handles everything; use “-type error” to write an error message
# This command handles everything; use “-type error” to write an error message
twapi::eventlog_log "My Test Event" -type info</lang>
twapi::eventlog_log "My Test Event" -type info</syntaxhighlight>


=={{header|VBScript}}==
=={{header|VBScript}}==
<syntaxhighlight lang="vb">
<lang vb>
Sub write_event(event_type,msg)
Sub write_event(event_type,msg)
Set objShell = CreateObject("WScript.Shell")
Set objShell = CreateObject("WScript.Shell")
Line 823: Line 823:


Call write_event("INFORMATION","This is a test information.")
Call write_event("INFORMATION","This is a test information.")
</syntaxhighlight>
</lang>


=={{header|Wren}}==
=={{header|Wren}}==
{{trans|Go}}
{{trans|Go}}
This embedded program is untested as I no longer have a working Windows machine but should work when run with administrative privileges - what can possibly go wrong?
This embedded program is untested as I no longer have a working Windows machine but should work when run with administrative privileges - what can possibly go wrong?
<lang ecmascript>/* write_to_windows_event_log.wren */
<syntaxhighlight lang="ecmascript">/* write_to_windows_event_log.wren */


class Windows {
class Windows {
Line 839: Line 839:
].join(" ")
].join(" ")


Windows.eventCreate(args)</lang>
Windows.eventCreate(args)</syntaxhighlight>
<br>
<br>
Now embed this script in the following C program, compile and run it.
Now embed this script in the following C program, compile and run it.
<lang c>#include <stdio.h>
<syntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
Line 925: Line 925:
free(script);
free(script);
return 0;
return 0;
}</lang>
}</syntaxhighlight>


=={{header|zkl}}==
=={{header|zkl}}==
{{trans|Clojure}}
{{trans|Clojure}}
<lang zkl>zkl: System.cmd(0'|eventcreate "/T" "INFORMATION" "/ID" "123" "/D" "Rosetta Code example"|)</lang>
<syntaxhighlight lang="zkl">zkl: System.cmd(0'|eventcreate "/T" "INFORMATION" "/ID" "123" "/D" "Rosetta Code example"|)</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>