bpl5000
asked on
Need to convert VB Script code to VB.NET
I have been using vb scripts and now I want to start using VB.NET. I have used VB6, but VB.NET is new to me. Can someone help me convert this vb script program to vb.net?
strInput = InputBox("Enter Group Name:")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("members.txt", True)
Const ADS_SCOPE_SUBTREE = 2
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") = 9999
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = "SELECT Name, ADSPath FROM 'LDAP://dc=bcsd,dc=local' WHERE objectCategory='group' "
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Set WshShell = WScript.CreateObject("WScript.Shell")
bFound = False
Do Until objRecordSet.EOF
If Trim(LCase(strInput)) = Trim(LCase(objRecordSet.Fields("Name").Value)) Then
bFound = True
Set oGroup = GetObject(objRecordSet.Fields("ADSPath").Value)
arrMemberOf = oGroup.GetEx("member")
For Each member In arrMemberOf
Set oUser = GetObject("LDAP://" & member)
objFile.WriteLine oUser.cN
Next
Exit Do
End If
objRecordSet.MoveNext
Loop
If bFound Then
objFile.Close
Call WshShell.Run("%comspec% /c sort.exe members.txt /o members.txt",0)
Call WshShell.Run("members.txt")
Else
MsgBox "Group """ & strInput & """ not found"
End If
ASKER
I was just looking to reuse the code I have. I added the reference for ADODB and I have the following code already converted...
This seems to be okay, but when I try to add the following lines...
objCommand.Properties("Pag e Size") = 9999
objCommand.Properties("Sea rchscope") = ADS_SCOPE_SUBTREE
These statements produce a "Property item is ReadOnly" error. I'm sure there is just a subtle difference to the way this statement needs to be done in vb.net, but I can't seem to find the correct way.
Dim strInput As String = TextBox1.Text
Dim objWriter As New System.IO.StreamWriter("members.txt")
Dim objConnection As New ADODB.Connection
Dim objCommand As New ADODB.Command
objConnection.Provider = "ADsDSOObject"
Const ADS_SCOPE_SUBTREE = 2
objConnection.Open("Active Directory Provider")
objCommand.ActiveConnection = objConnection
This seems to be okay, but when I try to add the following lines...
objCommand.Properties("Pag
objCommand.Properties("Sea
These statements produce a "Property item is ReadOnly" error. I'm sure there is just a subtle difference to the way this statement needs to be done in vb.net, but I can't seem to find the correct way.
If you want to reuse old VB6/VBScript code, in place of System.DirectoryServices code, then I don't believe that I am in a position to help you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That's awesome! I'm new to vb.net so can you explain what is meant by "Add a reference to namespace Microsoft.VisualBasic (Microsoft.VisualBasic.dll )"?
Thanks for the help!
Thanks for the help!
The System.DirectoryServices is useful when working with LDAP.
Sample:
Accessing LDAP User list using VB.NET
http://www.codeproject.com/KB/IP/LDAP_Using_VBnet.aspx
Open in new window