Jump to content

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


 Share

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: 3.2.4.9
Author: Chakka

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

#Include <Timers.au3>
Global Const $DESKTOP_SWITCHDESKTOP = 0x100

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

_WriteLogOn()

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

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

EndFunc

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

WEnd

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
    EndIf

    DllClose($hLockedDLL)

    If $iLocked Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc
Edited by chakka
Link to comment
Share on other sites

chakka,

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,

kylomas

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.

kylomas

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...