Solved

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

Posted on 2002-06-24
3
340 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

813 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