Solved

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

Posted on 2002-06-24
3
342 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…

726 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