Solved

How can I read these user attributes? (VBScript & ADSI)

Posted on 2002-06-24
3
337 Views
Last Modified: 2012-06-27
Answers to ANY of the following will get full points:

(Note I am using VBScript on Windows 2000 Active Directory so I think the answer will involve ADSI.)

1. How do I get the GUID for the currently logged on user?
or...
2. How do I get the CN attribute for the currently logged on user?
or...
2. How do I get the distinguishedName attribute for the currently logged on user?
or...
3. How do I find which Organisational Unit the currently logged on user is in?

0
Comment
Question by:chrismoh
  • 2
3 Comments
 
LVL 32

Accepted Solution

by:
bhess1 earned 75 total points
ID: 7105851
This *should* get you the distinguishedName attribute:

Set oConnection = CreateObject("ADODB.Connection")
Set oCommand = CreateObject("ADODB.Command")
oConnection.Provider = "ADsDSOObject")
oConnection.Open "Active Directory Provider"
Set oCommand.ActiveConnection = oConnection
Set oRoot = GetObject("LDAP://RootDSE")
sDomain = oRoot.Get("DefaultNamingContext")

Set oNet = CreateObject("Wscript.Network")
sUserID = ""
On Error Resume Next
Do While sUserID = ""
  Wscript.Sleep 5
  sUserID = oNet.UserName
Loop
On Error Goto 0

sQuery = "SELECT distinguishedName FROM 'LDAP://" & _
  sDomain & "' WHERE sAMAccountName = '" & sUserID & "'"
oCommand.CommandText = sQuery

Set oResults = oCommand.Execute
sDN = oResults.Fields("distinguishedName")
0
 

Author Comment

by:chrismoh
ID: 7105909
Thanks bhess1, it took me 2 days and 3 question submissions to get an that works.
If I had more points I'd give them to you.
0
 
LVL 32

Expert Comment

by:bhess1
ID: 7105918
Glad that I could help.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now