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 - Function Get_User_Name_AD()
-
Dim adoCommand, adoConnection, strBase, strFilter, strAttributes
-
-
Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strName, strCN, strLastLogin
-
-
-
-
' Setup ADO objects.
-
-
Set adoCommand = CreateObject("ADODB.Command")
-
Set adoConnection = CreateObject("ADODB.Connection")
-
adoConnection.Provider = "ADsDSOObject"
-
adoConnection.Open "Active Directory Provider"
-
adoCommand.ActiveConnection = adoConnection
-
-
-
-
' Search entire Active Directory domain.
-
-
Set objRootDSE = GetObject("LDAP://RootDSE")
-
-
strDNSDomain = objRootDSE.Get("defaultNamingContext")
-
strBase = "<LDAP://" & strDNSDomain & ">"
-
-
-
' Filter on user objects.
-
'KNOWN OBJECTS
-
'=======================================
-
'ObjectClass=user
-
'ObjectCategory=person
-
'CN
-
-
strFilter = "(&(objectCategory=person)(objectClass=user)(cn=Juan*))"
-
-
'EXAMPLES OF FILTER WHICH IS REALLY JUST A QUERY
-
'===========================================================
-
'"(&(objectCategory=person)(objectClass=user))"
-
'"(&(objectCategory=person)(objectClass=user)(cn=Joe*))"
-
'"(objectCategory=computer)"
-
'===========================================================
-
-
-
' Comma delimited list of attribute values to retrieve.
-
strAttributes = "sAMAccountName,cn,distinguishedName, mail, lastlogon"
-
'ATTRIBUTES
-
'===========================================================
-
'SAMAccountName CN DistinguishedName
-
'mail company givenName sn
-
'ADsPath name sAMAccountName telephoneNumber
-
-
-
' Construct the LDAP syntax query.
-
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
-
adoCommand.CommandText = strQuery
-
adoCommand.Properties("Page Size") = 100
-
adoCommand.Properties("Timeout") = 30
-
adoCommand.Properties("Cache Results") = False
-
-
-
-
' Run the query.
-
Set adoRecordset = adoCommand.Execute
-
-
-
' Enumerate the resulting recordset.
-
Do Until adoRecordset.EOF
-
-
' Retrieve values and display.
-
strName = adoRecordset.Fields("sAMAccountName").Value
-
-
strCN = adoRecordset.Fields("cn").Value
-
-
strLastLogin = adoRecordset.Fields("Lastlogon").Value
-
-
'Wscript.Echo "NT Name: " & strName & ", Common Name: " & strCN
-
Debug.Print "NT Name: " & strName & ", Common Name: " & strCN & "-" & strLastLogin
-
' Move to the next record in the recordset.
-
adoRecordset.MoveNext
-
Loop
-
-
-
-
' Clean up.
-
-
adoRecordset.Close
-
-
adoConnection.Close
-
-
-
-
End Function
-
1 4079
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
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Matt |
last post by:
Hi everybody,
does anyone know how to retrieve the computer name using ASP?
cheers...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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!!!
...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
| |