Sub Class_Globals
' --- Needs Javaobjects
Private NativeMe As JavaObject
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
NativeMe = Me
End Sub
Public Sub WriteWindowsEvent(buffer As String)
Dim s As String = NativeMe.RunMethod("WriteToWindowsEventLog", Array(buffer))
Log(s)
End Sub
#IF JAVA
/* See also https://www.jasonsamuel.com/2010/01/08/creating-a-custom-event-log-under-event-viewer-to-log-server-events/
* The first run time an error 1 is generated to solved this error status:
* Open a DOS box with the CMD command in Windows
* Paste the following command line (without the *)
* eventcreate /ID 5 /L APPLICATION /T INFORMATION /SO MYEVENTSOURCE /D \"My first log\"
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
public void WriteToWindowsEventLog(String argument) throws IOException, InterruptedException {
String osName = System.getProperty("os.name").toUpperCase(Locale.ENGLISH);
if (!osName.startsWith("WINDOWS")) {
System.err.println("Not windows");
return;
}
// System.out.println("Windows system found");
// https://www.jasonsamuel.com/2010/01/08/creating-a-custom-event-log-under-event-viewer-to-log-server-events/
// eventcreate /ID 1 /L APPLICATION /T INFORMATION /SO MYEVENTSOURCE /D "My first log"
Process process = Runtime.getRuntime().exec("eventcreate /ID 5 /L APPLICATION /T INFORMATION /SO MYEVENTSOURCE /D \"My first log\"");
process.waitFor(10, TimeUnit.SECONDS);
int exitValue = process.exitValue();
System.out.printf("Process exited with value %d\n", exitValue);
if (exitValue != 0) {
InputStream errorStream = process.getErrorStream();
String result = new BufferedReader(new InputStreamReader(errorStream))
.lines()
.collect(Collectors.joining("\n"));
System.err.println(result);
}
}
#End If