• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I get events from "Event Viewer" (Windows Administrative Tools) using Java?  RSS feed

 
Rogerio Kioshi
Ranch Hand
Posts: 690
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In Windows XP we can see all the events that happened in the computer:

Start --> Control Panel --> Performance and Maintenance --> Administrative Tools --> Event Viewer --> System Log


I'd like to get the time I started and the time I turned off my computer, through a java application.

I've heard that JNI might be used. Has someone already made something like this before?


Thank you.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Download Log4J - they have an appender which can add to the event log. Perhaps you can use that as a base for your own native code. The Log4J source code is freely available.
 
Josh Wild
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will have to use JNI. No standard Java API right now provides you this sort of feature to query the event log. Win32 SDK provides all features for system access. The API to read event log is there. You need to use that API from your JNI code.

Its a 2 step process:

1. Writing Java interfaces which make use of events, event categories (Application, System, Error etc) exposed in Java
2. Interface methods mapped to native JNI mehotds (native methods to be implemented in C++ or C using Win 32 SDK)


To carry out these steps you may have to study :

1. How JNI works
2. The Win 32 SDK API for EventLog

* While programming for EventLogs, you wll find lots of other interesting APIS like Performance counters, Windows Registry,.... .. Its actually very tempting
 
Josh Wild
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
.. And yes you will then be able to track log in, log out and other system events.. See there is a well designed structure of events... Each standard event like system login or logout has an event code. Once you are able to expose the low level Windows events to Java, you can access all sorts of information regarding an event.

The event code for 'System Login' is '6009' by the way
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!