Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VBScript help....

Posted on 2006-11-16
7
Medium Priority
?
495 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 1000 total points
ID: 17971175

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

Chris
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 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…
Suggested Courses

721 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