Link to home
Start Free TrialLog in
Avatar of chadmanvb
chadmanvb

asked on

Covert this vbs to .net

I'm trying to convert this from vbs to .net and not haveing much luck.

dim objRecordSet
dim objConnection
dim objCommand
dim user
dim strUser
dim strUserList
Set objFSO = CreateObject("Scripting.FileSystemObject")

'======== Get User ID 
user= InputBox("Enter the ID you want to check","Enter User ID")

'======== Set up ADODB Connection 
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "LDAP Provider;"
Set objCommand =   CreateObject("ADODB.Command")
Set objCommand.ActiveConnection = objConnection


'======== Query LDAP
Titleinfo = getTitle(user)


'======== Function to query LDAP and get the title info.
Function getTitle (userid)
 objCommand.CommandText =  "SELECT TITLE FROM 'LDAP://ldapapi/ou=people,o=my domain' WHERE unixid='" & userid & "'"
 Set objRecordSet = objCommand.Execute
 On Error Resume Next
 While Not objRecordSet.EOF
   For Each i in objRecordSet.fields
      For Each v in i.value

        WScript.Echo(v)	'the info I need
        
      Next
   Next
   objRecordSet.MoveNext
 Wend
 objConnection.close
End Function

wscript.quit

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chadmanvb
chadmanvb

ASKER

That worked!  Is there a better way i should be doing this?
We usually try to avoid late-binding (e.g. CreateObject) in .NET. There is nothing technically wrong with using it, but code is usually less error-prone with early-binding--that is, having the actual types of your objects known at compile time. You might look into some of the classes .NET has available for working with LDAP. Here are a few tutorials:

http://www.codeproject.com/Articles/4237/Querying-Active-Directory-using-NET-classes-and-LD
http://www.codeproject.com/Articles/9570/Querying-Microsoft-Active-Directory-Using-Microsof
Perfect!  Thanks for the help!