473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Retrieve the the computer a user last logged on too

maxamis4
295 Expert 100+
Hello folks,

Here is the backgroup. I am creating an agent that can find a user in LDAP and return the last logon date. Now i am not sure if with active directory you can user the SAMAccountName to retrieve the last computer the users logged on to. But i am looking for a place where i can learn this information. I was hoping someone out there could point me in the right direction.

Below is my code which i have been working on. It can retrieve the samaccountname information perfectly. I just can't get the lastlogon to work nor can i find how to bridge the name with a computer on LDAP . Any help would be great

Expand|Select|Wrap|Line Numbers
  1. Function Get_User_Name_AD()
  2. Dim adoCommand, adoConnection, strBase, strFilter, strAttributes
  3.  
  4. Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strName, strCN, strLastLogin
  5.  
  6.  
  7.  
  8. ' Setup ADO objects.
  9.  
  10. Set adoCommand = CreateObject("ADODB.Command")
  11. Set adoConnection = CreateObject("ADODB.Connection")
  12. adoConnection.Provider = "ADsDSOObject"
  13. adoConnection.Open "Active Directory Provider"
  14. adoCommand.ActiveConnection = adoConnection
  15.  
  16.  
  17.  
  18. ' Search entire Active Directory domain.
  19.  
  20. Set objRootDSE = GetObject("LDAP://RootDSE")
  21.  
  22. strDNSDomain = objRootDSE.Get("defaultNamingContext")
  23. strBase = "<LDAP://" & strDNSDomain & ">"
  24.  
  25.  
  26. ' Filter on user objects.
  27. 'KNOWN OBJECTS
  28. '=======================================
  29. 'ObjectClass=user
  30. 'ObjectCategory=person
  31. 'CN
  32.  
  33. strFilter = "(&(objectCategory=person)(objectClass=user)(cn=Juan*))"
  34.  
  35. 'EXAMPLES OF FILTER WHICH IS REALLY JUST A QUERY
  36. '===========================================================
  37. '"(&(objectCategory=person)(objectClass=user))"
  38. '"(&(objectCategory=person)(objectClass=user)(cn=Joe*))"
  39. '"(objectCategory=computer)"
  40. '===========================================================
  41.  
  42.  
  43. ' Comma delimited list of attribute values to retrieve.
  44. strAttributes = "sAMAccountName,cn,distinguishedName, mail, lastlogon"
  45. 'ATTRIBUTES
  46. '===========================================================
  47. 'SAMAccountName     CN          DistinguishedName
  48. 'mail               company     givenName               sn
  49. 'ADsPath            name        sAMAccountName          telephoneNumber
  50.  
  51.  
  52. ' Construct the LDAP syntax query.
  53. strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
  54. adoCommand.CommandText = strQuery
  55. adoCommand.Properties("Page Size") = 100
  56. adoCommand.Properties("Timeout") = 30
  57. adoCommand.Properties("Cache Results") = False
  58.  
  59.  
  60.  
  61. ' Run the query.
  62. Set adoRecordset = adoCommand.Execute
  63.  
  64.  
  65. ' Enumerate the resulting recordset.
  66. Do Until adoRecordset.EOF
  67.  
  68.     ' Retrieve values and display.
  69.     strName = adoRecordset.Fields("sAMAccountName").Value
  70.  
  71.     strCN = adoRecordset.Fields("cn").Value
  72.  
  73.     strLastLogin = adoRecordset.Fields("Lastlogon").Value
  74.  
  75.     'Wscript.Echo "NT Name: " & strName & ", Common Name: " & strCN
  76.     Debug.Print "NT Name: " & strName & ", Common Name: " & strCN & "-" & strLastLogin
  77.     ' Move to the next record in the recordset.
  78.     adoRecordset.MoveNext
  79. Loop
  80.  
  81.  
  82.  
  83. ' Clean up.
  84.  
  85. adoRecordset.Close
  86.  
  87. adoConnection.Close
  88.  
  89.  
  90.  
  91. End Function
  92.  
Sep 8 '07 #1
1 4079
maxamis4
295 Expert 100+
In my efforts to figure this out I have found that Microsft does not have this feature most admins use scripts that go back and point the user back to the actual computer he or she is logged into. If anyone knows how to figure this out please let me know thanks
Nov 9 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Matt | last post by:
Hi everybody, does anyone know how to retrieve the computer name using ASP? cheers...
1
by: Bishop | last post by:
I see the LastLogin property exists: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adschema/adschema/a_lastlogon.asp but when I query it, it always returns null. Anyone know...
8
by: Dutchy | last post by:
Dear reader, In an attempt to obtain the path to the quick-launch-folder in order to create a shortcut to my application-updates during installation , I thought to: 1- check if quick launch...
1
by: Paul W | last post by:
I've got Forms Authentication up and running. The starting page for the app. is default.aspx. I want to display on the top of this form a 'You are logged in as Fredxyz' message. If the user is a...
5
by: tjonsek | last post by:
I am trying to pull the user logon info in an asp.net application to use as a security stamp when someone completes a function. So far, I am able to retrieve the computer name. This is, however,...
3
by: Dave Smithz | last post by:
Hi there, I have a website where users can log into. This users sessions as I believe most people use when implementing a login section of a website (each php page first checks a valid parameter...
1
by: Alex | last post by:
Hello All, Is it possible to get when a user logged in the network? I'm interested in time (Logged in and logged out). I'll be using VB 2005 and connecting to Active Directory. Thanks!!! ...
0
xxoulmate
by: xxoulmate | last post by:
what are the Other way to retrieve the user of computer over the network, except of putting it on the database. i am using OS 98., what im getting is just only the user currently logged on the...
9
by: Gordon | last post by:
I want to add a feature to a project I'm working on where i have multiple users set up on my Postgres database with varying levels of access. At the bare minimum there will be a login user who...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.