Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Iron Speed
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old September 8th, 2007, 10:22 PM
maxamis4's Avatar
maxamis4 maxamis4 is offline
Excel at any cost
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2005
Location: metropolitan area
Posts: 229 maxamis4 User rank is Corporal (100 - 500 Reputation Level)maxamis4 User rank is Corporal (100 - 500 Reputation Level)maxamis4 User rank is Corporal (100 - 500 Reputation Level)maxamis4 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 16 h 22 m 16 sec
Reputation Power: 6
Send a message via AIM to maxamis4 Send a message via MSN to maxamis4 Send a message via Yahoo to maxamis4
LDAP Query to find a users computer

I am doing this in Access, but its more VB than anything else so figured it would be beter to post here.

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

Code:
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


Reply With Quote
  #2  
Old April 18th, 2008, 08:20 PM
maxamis4's Avatar
maxamis4 maxamis4 is offline
Excel at any cost
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2005
Location: metropolitan area
Posts: 229 maxamis4 User rank is Corporal (100 - 500 Reputation Level)maxamis4 User rank is Corporal (100 - 500 Reputation Level)maxamis4 User rank is Corporal (100 - 500 Reputation Level)maxamis4 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 16 h 22 m 16 sec
Reputation Power: 6
Send a message via AIM to maxamis4 Send a message via MSN to maxamis4 Send a message via Yahoo to maxamis4
Only Answer Found

From what the web says the only method in which to perform this is to create a login script which stores this in a textfile or database. Other than that LDAP does not link the two.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > LDAP Query to find a users computer


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway