Using Active Directory

  • Thread starter Thread starter Patrick McGuire
  • Start date Start date
P

Patrick McGuire

I am trying to load a combobox with all the existing
users on a computer (there are currently 4 users). I'm
using the following code:

Imports ActiveDirectory
..
..
..
Private Sub Form_Load

Dim cont As IADsContainer
Dim user As IADsUser
Dim strFilter() As String

cont = GetObject("WinNT://VAIO" & ",computer")
If (Err.Number <> 0) Then
HandleErrors(Err.Number, "on GetObject
method")
End If
ReDim strFilter(0)
strFilter(0) = "User"
cont.Filter = strFilter
If (Err.Number <> 0) Then
HandleErrors(Err.Number, "on
IADsContainer::Filter method")
End If

For Each user In cont
selectUser.Items.Add(user.Name)
Next
selectUser.Text = selectUser.Items(0)

end sub

The problem is the ForEach/Next loop. After executing
successfully for each of the four usrs, the loop throws
an invalid cast exception. I can't use a counter because
cont.count throws a "not implemented exception"

How do I work around this?

Thanks for the help

Pat
 
The problem is the ForEach/Next loop. After executing
successfully for each of the four usrs, the loop throws
an invalid cast exception. I can't use a counter because
cont.count throws a "not implemented exception"

Hi there,

As a matter of interest how comes you are not using Try blocks? You are
looking for errors by examining an error number, which seems to be a bit VB6
if my memory serves me correctly. i.e.

---------

try
cont = GetObject("WinNT://VAIO" & ",computer")
catch ex as exception
'handle error here
end try

...

try
cont.Filter = strFilter
catch ex as exception
'handle error here
end try

---------

I'm not to sure about your loop error though as I can't really test it
with my current setup. But maybe this information will be usefull none the
less. But small questions, what type is

* user.Name

Is this a string ? And what is selectUser? is that a collection,
arraylist, listview? Is the error actually occuring when it tries to add to
selectUser or when it initiates the loop?

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Slow internet connection?
Having problems with you job?
You're marriage is on the rocks?
You can't sleep at night?
You have a drink and drugs addiction?
You are sexually impotent?
Then enable Option Strict!
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
Back
Top