We help IT Professionals succeed at work.

Read logoff and logon times for windows with delphi

hush021299
hush021299 asked
on
Where do I find the log file which logs windows xp lonon and logoff times.
How can I read the file using delphi code
Comment
Watch Question

Author

Commented:
Changed failure in the head line
Lukasz Zielinskisoftware developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
you can find it in system log (Security).
with delphi you can do this with:
OpenEventLog() and ReadEventLog() functions.

If there will be no one with ready code I'll post some here later this evening.

ziolko.
software developer
CERTIFIED EXPERT
Top Expert 2008
Commented:
check out inthe's solution:
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_20095952.html

just change 'Application' to 'Security' you will also have to browse for logon/logoff event log entries

ziolko.
Or a simple idea.

Create a small application that will start on windows startup (for example: put a shortcut in the start menu to start it automatically or via the registry).

The application can start and minimize to the try.

Everytime the application starts save the date and time on a file on a specified location of your choice.

Then inside a timer you can try something like this to detect windows shutdown:

http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_10305197.html?sfQueryTermInfo=1+detect+shutdown

When detected that add this entry date and time to your file.

This is a very simple way to do it and you will have a log of all logins and shutdowns and you can even add the username to the log.  

Author

Commented:
Thanks I will check that.
The Idea from Stecenz is already implemented in an old program of mine: WinExit
But often the shutdown is "incontroled", sometimes I start with hibernated machine
so I search for windows log

Author

Commented:
I failed early
in windows/security/log there is no system.log
Lukasz Zielinskisoftware developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
>>in windows/security/log there is no system.log

nope there's no system.log but there is \Windows\System32\config\SecEvent.evt

but you won't be anle to read directly form file use inthe's solution from link I posted to read from system log not from file on disk

ziolko.

Author

Commented:
I will try this one