Solved

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

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

808 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