Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Querying Active Directory

Posted on 2004-10-29
6
Medium Priority
?
187 Views
Last Modified: 2010-05-02
I am trying to get my script to return details from Active Directory based on the currently logged in user, I have the script to query AD and it works great and gives me every user, how can I restrict the search to provide just the logged in user?

here is what I have

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

objCommand.CommandText = _
 "<LDAP://ou=users,dc=server,dc=comany,dc=world,dc=com>;(objectCategory=user)" _
  & ";name,sAMAccountName;subtree"
Set objRecordSet = objCommand.Execute

While Not objRecordSet.EOF
 Wscript.Echo objRecordSet.Fields("name")
 Wscript.Echo objRecordSet.Fields("sAMAccountName")
 objRecordSet.MoveNext
Wend

objConnection.Close
0
Comment
Question by:nemesis1210
[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
  • 3
  • 3
6 Comments
 
LVL 48

Expert Comment

by:Mikal613
ID: 12444557
Function NameOfUser() As String
NameOfUser = Environ("UserName")
End Function

Will get you the Current user so loop till you find it o
0
 
LVL 2

Author Comment

by:nemesis1210
ID: 12444618
Where in the script do I put it and how do I tell it to loop till it finds it?
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 12444663
While Not objRecordSet.EOF
   IF  objRecordSet.Fields("name") = NameOfUser then
 
        Wscript.Echo objRecordSet.Fields("name")
        Wscript.Echo objRecordSet.Fields("sAMAccountName")
   end if
 objRecordSet.MoveNext
Wend
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Author Comment

by:nemesis1210
ID: 12444772
it did not like your function command, is it a VB or VB Script function had that problem already I need VB Script

0
 
LVL 48

Accepted Solution

by:
Mikal613 earned 2000 total points
ID: 12444811

Set wshShell = CreateObject("WScript.Shell")
strUser = wshShell.ExpandEnvironmentStrings("%USERNAME%")
WScript.Echo "Current User: " & strUser

 IF  objRecordSet.Fields("name") = strUser then
 
        Wscript.Echo objRecordSet.Fields("name")
        Wscript.Echo objRecordSet.Fields("sAMAccountName")
   end if

0
 
LVL 2

Author Comment

by:nemesis1210
ID: 12444900
I managed to get it to work with

Dim strUserName

getusername
Sub GetUserName()
  Dim WSHNetwork  

  Set WSHNetwork = CreateObject("WScript.Network")
  strUserName = WSHNetwork.username
  msgbox strusername
End Sub

however you are the only person to help I am sure your method will work also so the points are yours

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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 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…
Suggested Courses

636 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