Determine the Last Logging Time on to a computer

Sometimes you might be wondering to know who has logged on your computer when you were busy with your work or when you were not at home. Now, you can get the details of your Log in on your computer without using any third party applications. Windows itself has a feature to store the details of your login and this which is least known to anyone. Here is the tutorial how you can get the details about who has been using your computer.

logging time computer
All login history or information is saved in Windows. You can easily access it using VB Script. There is a WMI object called Win32_NetworkLoginProfile. This object allows you to see all the users that have logged on to your system along with their information.

Here is the simple VB script that shows who all has logged into your system.

Set objWMIService = GetObject(“winmgmts:\\.\root\cimv2″)
Set colItems = objWMIService.ExecQuery(“Select * from Win32_NetworkLoginProfile”)
For Each objItem in colItems
Wscript.Echo objItem.Name
Next

The output will list accounts like NT AUTHORITY\SYSTEM or NT AUTHORITY\LOCAL SERVICE

You can browse the Microsoft website to see all the options provided in the Win32_NetworkLogonProfile object
Look for UserType variable which will be set to the string Normal Account for all standard logon accounts
Using this info, you can change the script to not show those accounts

Set objWMIService = GetObject(“winmgmts:\\.\root\cimv2″)
Set colItems = objWMIService.ExecQuery(“Select * from Win32_NetworkLoginProfile”)
For Each objItem in colItems
if (objItem.UserType = “Normal Account”) then
Wscript.Echo objItem.Name
end if
Next

How to determine who was the last to logon? This will be known from the LastLogon field. The bigger this number is, the later the logon.

You can change the script to see only the last logon

Set objWMIService = GetObject(“winmgmts:\\.\root\cimv2″)
Set colItems = objWMIService.ExecQuery(“Select * from Win32_NetworkLoginProfile”)
iLastLogon = 0
sLastUser = “Unknown”
For Each objItem in colItems
if (objItem.UserType = “Normal Account”) then
if (iLastLogon
iLastLogon = objItem.LastLogon
sLastUser = objItem.Name
end if
end if
Next

Upon completion you will be notified with the time of last log on on your computer.

You can get the time and date of your last log on on your computer. But make sure that you are logged in as Admin to change the VB script on your computer. If in case anyone has logged in as Admin then you can get the details by logging as another user if you log in as admin then this will mention you as the last log in user.

Upon following the above procedure you can easily get the details of when your computer was last logged in without using any third party software.

Advertisement

No comments yet.

Leave a Comment