Determining the last computer an account logged into

Here's a somewhat interesting problem I hope someone might have an easy solution too:

We have the standard of naming computers after their users (where possible), which makes it easy to group them in departmental OU's and such. Recently at my work there has been some high turnover, and techs have been somewhat lax in renaming computers to reflect the actual person that is using the machine. For example, you might have a machine named "juserxp", even though Joe User quit 3 months ago, and now Sally Snide is now using the machine.

Using the usrstat.exe program in the Resource Kit, I can of course determine the last login of a particular user, but so far have not found a way to determine which machine the user logged into. Security Event Log would reveal this information I imagine, and if I have too I thought about writing a login script that writes the machine name to a text file somewhere at login, but I'm looking for a more "on the fly" solution. A script or tool that could be run at my console command prompt perhaps.

Longshot I suppose, but if anyone has any ideas I would appreciate it.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David LeeCommented:
Other than the solutions you've already mentioned I don't know of any better way to determine who was last logged on to a given computer.  If you'd like to know who is currently logged on to a given computer, then the script below will tell you that.  It uses WMI (Windows Management Instrumentation) to determine that.  All you need to do to make use of the script is change strComputer to the name of the computer you want to check.  A more advanced version of the script would be to create an array of computer names to check and have the script check them all in sequence.

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For Each objItem in colItems
    Wscript.Echo "Computer Name: " & objItem.Name
    Wscript.Echo "UserName: " & objItem.UserName

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mvogtsAuthor Commented:
Not exactly what I was looking for, but that script will be useful, and it looks like this question is sort of tapped out, so points awarded.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows 2000

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.