Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Last logon time???

Status
Not open for further replies.

gussy1

Technical User
Dec 22, 2002
63
IE
Could anyone tell me how I can write a VB Script or Batch FIle to display the username and last log-in time for each user logging onto a local machine - regardless of group.

Cheers
 
Gussy

This will give you something to start on - if your users are Domain accounts then this will only tell you the last time they logged onto the Domain not a particular PC. If they are local accounts it will work perfectly just supply the ComputerName for strDomain

strDomain = inputbox ("Enter Domain")
strUserName = inputbox ("Enter UserName")
Set myUser = GetObject("WinNT://" & domain & "/" &= strUsername & ",user")
msgbox myuser.LastLogin

-Sunny
 
I get an error that the object doesn't support the property or method "LastLogin" ? Because I want this to work on a local machine only, can I leave out the domain info?
 
Gussy

What version of Windows are you using? I have only tested this script on Win2K and NT4.

Try replacing "LastLogin" with "Description" to see if you can return this for a user.

You cannot drop "Domain" - this is not why you are getting an error - are you running the script as posted?

-Sunny
 
Yes I ran it exactly as posted on XP Pro. I'll try "Description".

Cheers
 
You need to drop the equals sign after the ampersand in front of strUsername


strDomain = inputbox ("Enter Domain")
strUserName = inputbox ("Enter UserName")
Set myUser = GetObject("WinNT://" & domain & "/" & strUsername & ",user")
msgbox myuser.LastLogin
 
strDomain = inputbox ("Enter Domain")
strUserName = inputbox ("Enter UserName")
Set myUser = GetObject("WinNT://" & strDomain & "/" & strUsername & ",user")
msgbox myuser.LastLogin

whoops, almost missed the "domain" should be strDomain
 
That works now on the domain at work. Is it possible to get this to work on a LOCAL machine with NO domain. Surely the registry keeps a record of logon tomes somewhere?

Thanks
 
What is the OS?
Have you tried the script using the Computer Name as the Domain?

Windows 2000 lists the Computer Name as the Domain in its "User and Passwords" component in control panel, so that might work.
I'm not sure with 95/98/Me machines, probably not.
 
I have XP Pro so i'll try that.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top