• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Need Help: VBA Code to Capture Windows System Lock/Unlock Time

Mahantesh

Member
Hi Team,

I would like to design a macro to capture system Lock ( Win + L) and Unlock time (Ctrl+Alt+Del).

like below:
_______Column A_______________ _____Column B__________
5/27/2019 22:01:01 PM Locked
5/27/2019 22:01:21 PM Unlocked

I want this to be captured in different Workbook saved in different path , row by row by current Windows user.

Please help!

regards,
Mahantesh
 
Logon is easy using WMI.
Ex:
Code:
Sub Demo()
Dim sDomain As String, sUser As String
Dim WMI As Object, UserInfo As Object

sDomain = "'" & Environ("UserDomain")
sUser = sDomain & "\" & Environ("UserName") & "'"
Set WMI = GetObject("winmgmts:")
Set UserAtt = WMI.Get("Win32_NetworkLoginProfile.Name=" & sUser)

Debug.Print Format(Left(Data.LastLogOn, 14), "0000\/00\/00 00:00:00")
End Sub

However, it isn't so straight forward... for LogOff/Lock.

For that you'd need to have logging enabled by the NetworkAdmin or Local Admin. By default LogOff/Lock isn't logged as far as I know.

I assume this is for local terminals (as you mention Lock time).
Personally, I'd recommend working with Network Admin to set up GPO script to run on user action to write to log (Scheduled Task + CMD script) and read data from text file using Excel.

If it's domain level... you'd need Audit Policy set up by Network Admin, and have them set up script to export log (using filter conditions on events) to designated location and read from there.

Note: If it's for specific terminal only. You can set up scheduled task to run CMD script. However, you may need elevated access (Local Admin) to do so.
 
Back
Top