Hi
I am looking for a simple vbs code to add to my startup folder which will tell me who logged on to the the pc last, can anyone help please.
Best Regards
Braddy
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Windows » Windows 7 » Questions: Windows 7 » Last Logon Code
Simple google search;
http://www.rlmueller.net/Last%20Logon.htm
VBScript to get users last login
GOOGLE
Programs:
True Last Logon 2.9
RealLastLogon
Looks like the links Clint provided will tell you the last time a given user logged in, and most of those depend on Active Directory. But Braddy, isn’t your goal to find the account name of the person who logged onto your PC prior to you?
I know that you can find that information in the Security Log (Computer | Manage | System Tools | Event Viewer | Windows logs). Back up to the second occurrence of the Eventlog Service Shutdown entry (event ID 1100) [actually, the Security State change entry #4608 that denotes the lsass.exe startup might be even better], then go forward to the first Logon entry (ID # 4624) and look at the credentials – that’s who logged on prior to you.
Seems like it should not be that hard to come up with a PowerShell script to do this, perhaps even list the last N accounts that logged in. Seems like a worthwhile project, I’ll post the script when I have it (might take a few days tho).
Hi
Thanks to all who replied but I have settled for this simple vbs file, added to my startup folder is just what I was looking for.
Option Explicit
Dim objWMIService, colItems, WshNetwork, strComputer
Dim objUser, objItem, dtmLastLogin, strLogonInfo
Set WshNetwork = CreateObject(“Wscript.Network”)
strComputer = WshNetwork.ComputerName
Set objWMIService = GetObject(“winmgmts:\” & strComputer & “rootcimv2”)
Set colItems = objWMIService.ExecQuery _
(“Select * from Win32_UserAccount Where Domain = ‘” & strComputer & “‘”)
For Each objItem in colItems
dtmLastLogin = “”
On Error Resume Next
Set objUser = GetObject(“WinNT://” & strComputer _
& “/” & objItem.Name & “,user”)
dtmLastLogin = objUser.lastLogin
On Error Goto 0
strLogonInfo = strLogonInfo & vbCrLf & objItem.Name & “: ” & dtmLastLogin
Next
MsgBox strLogonInfo, vbOKOnly + vbInformation, “Last Logon Information for Local Users”
Regards
Braddy
Hi All,
I tried Braddy’s script and it worked just fine. However, I noticed a logon to the Guest Account which, as I verified, is disabled!
Here’s the info from the Security Log:
Audit Success 8/25/2010 11:03:06 AM Microsoft Windows security auditing. 4624 Logon Details: Subject: Security ID: Inspiron15-i5userid Account Name: Bruce Account Domain: Inspiron15-i5 Logon ID: 0x63810 Logon Type: 3 New Logon: Security ID: Inspiron15-i5Guest Account Name: Guest Account Domain: Inspiron15-i5 Logon ID: 0x2b6feb Logon GUID: {00000000-0000-0000-0000-000000000000}
Immediately following was:
Audit Success 8/25/2010 11:03:06 AM Microsoft Windows security auditing. 4634 Logoff Details: An account was logged off. Subject: Security ID: Inspiron15-i5Guest Account Name: Guest Account Domain: Inspiron15-i5 Logon ID: 0x2b6feb Logon Type: 3
Anyone have an idea what’s going on?
And here is a quick-and-dirty PowerShell script that gives the last 10 logons. You can add it to your Startup menu if you like.
param($count = 10) $lastLogon = $null filter RecallLogon { #"]" + $_.ReplacementStrings[9] + "[" if ($_.ReplacementStrings[9] -eq "User32 ") {$script:lastLogon = $_} else {$_} } filter PrintLogon { if ($_.InstanceID -eq 1100 -and $lastLogon) { "User " + $script:lastLogon.ReplacementStrings[5] + " logged in at " + $lastLogon.TimeGenerated } } get-eventlog -logname security | where {$_.EventID -eq 1100 -or $_.EventID -eq 4624} | RecallLogon | PrintLogon | Select -first $count
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.
Notifications