Jump to content
Sign in to follow this  

Simple System Activity Log. Guide me plz... standardize

Recommended Posts


Hi all,

I'm very new here

I'm trying to make a simple user activity logger.

To log User Logon, Logoff & Lock

Somehow I've reached up to here. but I'm not able to log logOff/Shutdown time with this. I could see OnAutoItExitRegister would do this job. but I failed to implement.

Somebody please help me to implement (and to standardize this code also)

#cs ----------------------------------------------------------------------------

AutoIt Version:
Author: Chakka

#ce ----------------------------------------------------------------------------

#Include <Timers.au3>

Global $log = @ScriptDir&"log.txt", $newData , $userDay = @MON & "/" & @MDAY & "/" & @YEAR & " " & @UserName & "2"


Func _WriteLogOn()
$newData = "LogOn at " & @HOUR & ":" & @MIN & ":" & @SEC

Func _WriteLog()
$logData = IniRead($log, $userDay, "", "")
IniWrite($log, $userDay,"",$logData & @CRLF & $newData)


While 1
    ; If Locked the system
    If _CheckLocked() Then
        $newData = "Locked " & @HOUR & ":" & @MIN & ":" & @SEC
        ; Now idle the script until the user login back
        While _CheckLocked()
            Sleep (10)
        ; Assume active
        $newData = "Active at " & @HOUR & ":" & @MIN & ":" & @SEC


Func _CheckLocked()
    $hLockedDLL = DllOpen("user32.dll")
    $hDesktop = DllCall($hLockedDLL, "int", "OpenDesktop", "str", "Default", "int", 0, "int", 0, "int", $DESKTOP_SWITCHDESKTOP)
    $ret = DllCall($hLockedDLL, "int", "SwitchDesktop", "int", $hDesktop[0])
    DllCall($hLockedDLL, "int", "CloseDesktop", "int", $hDesktop[0])

    If $ret[0] = 0 Then
        $iLocked = 1
    ElseIf $ret[0] = 1 Then
        $iLocked = 0


    If $iLocked Then
        Return 1
        Return 0
Edited by chakka

Share this post

Link to post
Share on other sites


First update your version of autoit.

Secondly, define what environment this is to run in, multi-user pc, server, run remotely, run as logon script, etc.

And finally, you can register system shutdown messages like this

GUIRegisterMsg(0x0016, "sys_fini")
GUIRegisterMsg(0x0011, "sys_fini")

Good Luck,


Edit: sorry, got pulled away. Look up guiregistermsg in the help file. The 2nd parm of the function call is the function that you wish to execute when the message occurs. One, or both of these messages can occur at shutdown, I don't recall the particulars, but if you do a search on queryendsession you will find the explanation.

Also, not sure what you mean by "standardizing" a script. There are some adhoc conventions that people on this forum follow, but nothing formalized, that I know of.


Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post

Link to post
Share on other sites

kylomas thanks for ur helping hand . It was my first AutoIt script.

Share this post

Link to post
Share on other sites

Suggestion: check the help file for _FileWriteLog. It may help you write cleaner code.

RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this