Solved

VBScript help....

Posted on 2006-11-16
7
487 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

912 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

16 Experts available now in Live!

Get 1:1 Help Now