Enumerate User Accounts of a Remote Machine

Hello,

I have written a console program that takes in a list of computer names. I need it to go through a loop using each computername and bring back an arraylist of all the Users that are defined on that remote machine.  I did a search through experts exchange and found this http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21760016.html
I am using the solution given in this PAQs, but for me what is happening is that it takes a very LOOONG time to run and it may be getting user accounts from more than one machine.  Please see the image attached from a debug session.  When it crashed it had 5220 as the length of the arraylist.  Ther is no way that one computername has that many accounts defined on it.  Could it getting the accounts from the entire domain ? I am attaching the code snippet I am using as well as the Log4net log.   Hope some one can help me with this.  active_photo was the expert who answered the question I am referred to above, but anyone else, please help.      

All I need it to do is to bring back the Users defined on 1 machine that I am sending in through the parameter.  I then have to go through the arraylist and figure out if a particular user account is within it and then do other stuff.  PLEASE HELP.  msyed1.  
Public Function EnumerateLocalAccounts(ByVal machineName As String, ByRef bolIsAccessDenied As Boolean) As ArrayList
        ''''''bolIsAccessDenied is ByRef
 
        Dim arlArrayOfAccounts As New ArrayList
        Dim strAccount As String
 
        Dim strNumbers As String = "0,1,2,3,4,5,6,7,8,9"
        Dim strSplitNumbers() As String = Split(strNumbers, ",")
        Dim i As Integer = 0
 
        'If this is an IP Address....bypass
        For i = 0 To strSplitNumbers.GetUpperBound(0)
            If machineName.StartsWith(strSplitNumbers(i)) Then
                Return arlArrayOfAccounts
            End If
        Next
   
        Try
 
            Dim query As ObjectQuery
            Dim searcher As ManagementObjectSearcher
            Dim scope As ManagementScope = New ManagementScope
            Dim strComputerName As String = machineName
            Dim queryCollection As ManagementObjectCollection
            'Dim options As ConnectionOptions = New ConnectionOptions
            'options.Username = "testAccount"
            'options.Password = "fooo"
            'scope = New ManagementScope("\\" & strComputerName & "\root\cimv2", options)
 
            scope = New ManagementScope("\\" & strComputerName & "\root\cimv2")
 
            scope.Connect()
            query = New ObjectQuery("SELECT * FROM Win32_Account")
            searcher = New ManagementObjectSearcher(scope, query)
            queryCollection = searcher.Get()
            For Each m As ManagementObject In queryCollection
                'ListBox1.Items.Add(m("caption"))
                strAccount = (m.Item("Name"))
                arlArrayOfAccounts.Add(strAccount)
            Next
 
            Return arlArrayOfAccounts
 
        Catch uae As UnauthorizedAccessException
            log.Error("Error occurred on machinename: " & machineName & " - " & uae.Message)
            bolIsAccessDenied = True
 
        Catch ex As Exception
            log.Error("Error occurred: " & ex.Message)
        End Try
 
    End Function
 
 
Log4Net:
2009-05-24 10:31:47,969 [4996] ERROR [app(TaskRunnerAccountDiscovery.exe) class(TaskRunnerAccountDiscovery) method(EnumerateLocalAccounts) line(203)] - Error occurred: The remote procedure call failed.
2009-05-24 10:34:39,508 [4996] ERROR [app(TaskRunnerAccountDiscovery.exe) class(TaskRunnerAccountDiscovery) method(Main) line(119)] - Error: Object reference not set to an instance of an object.

Open in new window

DebugSession.doc
msyed1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kaylanreilorCommented:
Probably you're enumerating all the user account that the computer can know from the whole domain !
If you have a look to the following discussion (http://www.pcreview.co.uk/forums/thread-531890.php), you'll see that one of the propositions made if to add a WHERE close to the WMI query:
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_UserAccount Where Domain = '" & strComputer & "'")
So, let's try this.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kaylanreilorCommented:
Is it possible that you give some news after the thread I posted ? If other people face the same issue they would probably need to know what do you think about my answer !
0
msyed1Author Commented:
Sorry, I haven't been able to test this out yet....but I willl soon. msyed1.    
0
msyed1Author Commented:
kaylanreilor:  I still haven't had the opportunity to test your suggestion.  But I wanted to go ahead and award you the points.  Thank you for your assistance and I am sorry for the delay.  msyed1.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.