Solved

VBScript help....

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

803 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