Solved

VBScript help....

Posted on 2006-11-16
7
491 Views
Last Modified: 2008-02-01
Hi All,

I've cobled together a VBScript to help our DBA lookup peoples usernames..... basically the DBA is prompted with a MsgBox to enter the part of the user name they know - e.g. Hughes....  this returns a list of users with Hughes in their name.


I'm a bit stuck on how to add the finishing touches, and am hoping for a VBS guru to help me out... :o)


These are what i'd like to add....

1) instead of a echo'ing the usernames, i want to put them all into one notepad.exe file.
2) have the LDAP search run under different user credentails....



Script below;



___________________________________________________


  Dim Name

  iName = InputBox("Please enter your keyword to search by: ")


On Error Resume Next


Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000

objCommand.CommandText = _
    "<LDAP://dc=MyDomain,dc=local>;(&(objectCategory=person)(objectClass=user)(name=*" & iNAME & _
        "*));Name;Subtree"  
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Do Until objRecordSet.EOF
    Wscript.Echo objRecordSet.Fields("Name").Value
    objRecordSet.MoveNext
Loop


Wscript.Echo "Finshed searching"

WScript.Sleep 1000000


0
Comment
Question by:detox1978
[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
  • 2
7 Comments
 
LVL 2

Author Comment

by:detox1978
ID: 17964107

I've found this, so it should be possible....

http://www.microsoft.com/technet/scriptcenter/resources/qanda/apr06/hey0428.mspx



....i'm just not sure how to integrate it.
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 17964568

It's not much help for searching under different credentials unfortunately. Is RunAs all you wanted to do for this? You could add that to a batch file if so...

As for writing it to Notepad, you could write it all to a file then call Notepad and the filename?


  Dim Name

  iName = InputBox("Please enter your keyword to search by: ")


On Error Resume Next

Set objFileSystem = CreateObject("Scripting.FileSystemObject")
Set objFile = objFileSystem.CreateTextFile("Users.txt", True)


Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000

objCommand.CommandText = _
    "<LDAP://dc=MyDomain,dc=local>;(&(objectCategory=person)(objectClass=user)(name=*" & iNAME & _
        "*));Name;Subtree"  
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Do Until objRecordSet.EOF
    Wscript.Echo objRecordSet.Fields("Name").Value
    objFile.WriteLine objRecordSet.Fields("name")
    objRecordSet.MoveNext
Loop

Set objShell = CreateObject("WScript.Shell")
objShell.Run "notepad.exe Users.txt", 9, False
Set objShell = Nothing

Set objFile = Nothing
Set objFileSystem = Nothing

Wscript.Echo "Finshed searching"

WScript.Sleep 1000000
0
 
LVL 16

Expert Comment

by:Redwulf__53
ID: 17966003
Why would you want to run it under different credentials? All Domain Users can query the common attributes such as user name, telephone number etc.  in AD....
0
 
LVL 2

Author Comment

by:detox1978
ID: 17969343
Can they query usernames? i didn't think they could get that info?


If they can i dont need the runas...... :-)


I'll check...
0
 
LVL 71

Accepted Solution

by:
Chris Dent earned 500 total points
ID: 17971175

Any user should be able to. Administrative access is rarely needed for just looking.

Chris
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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…
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…
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…

738 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