Solved

VBScript help....

Posted on 2006-11-16
7
484 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
  • 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 70

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 70

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

757 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

17 Experts available now in Live!

Get 1:1 Help Now