Jump to content
Sign in to follow this  

get event "lock computer" and "unlock computer"

Recommended Posts

Hi all,

I have already done a lot of automation with autoit (AD, Execl, unattended installations),

but unfortunately I have no experience with reading windows events.

So my problem is I want to read out when the computer gets locked or unlocked the hole day long (from event logging?)

So I searched a bit and found this VB code which looked very nice:

Public Class Form1

    Private Declare Function WTSRegisterSessionNotification Lib "Wtsapi32" (ByVal hWnd As IntPtr, ByVal THISSESS As Integer) As Integer
    Private Declare Function WTSUnRegisterSessionNotification Lib "Wtsapi32" (ByVal hWnd As IntPtr) As Integer

    Private Const NOTIFY_FOR_ALL_SESSIONS As Integer = 1
    Private Const NOTIFY_FOR_THIS_SESSION As Integer = 0
    Private Const WM_WTSSESSION_CHANGE As Integer = &H2B1

    Private Enum WTS
        REMOTE_CONNECT = 3
        SESSION_LOGON = 5
        SESSION_LOGOFF = 6
        SESSION_LOCK = 7
        SESSION_UNLOCK = 8
    End Enum

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        WTSRegisterSessionNotification(Me.Handle, NOTIFY_FOR_ALL_SESSIONS)
    End Sub

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        Select Case m.Msg
                Select Case m.WParam.ToInt32
                    Case WTS.CONSOLE_CONNECT
                        Debug.Print("A session was connected to the console session.")
                    Case WTS.CONSOLE_DISCONNECT
                        Debug.Print("A session was disconnected from the console session.")
                    Case WTS.REMOTE_CONNECT
                        Debug.Print("A session was connected to the remote session.")
                    Case WTS.REMOTE_DISCONNECT
                        Debug.Print("A session was disconnected from the remote session.")
                    Case WTS.SESSION_LOGON
                        Debug.Print("A user has logged on to the session.")
                    Case WTS.SESSION_LOGOFF
                        Debug.Print("A user has logged off the session.")
                    Case WTS.SESSION_LOCK
                        Debug.Print("A session has been locked.")
                    Case WTS.SESSION_UNLOCK
                        Debug.Print("A session has been unlocked.")
                    Case WTS.SESSION_REMOTE_CONTROL
                        Debug.Print("A session has changed its remote controlled status. To determine the status, call GetSystemMetrics and check the SM_REMOTECONTROL metric.")
                End Select

        End Select

    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    End Sub

End Class

also a mark to http://msdn.microsoft.com/en-us/library/aa383828.aspx

So my problem is that I dont know VB well and want to write this in autoit.

Can somebody help me with the basic so that I can read out the time when a computer gets locked?

Thanks for help!

br devilman

Share this post

Link to post
Share on other sites

Take a look at this

GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...