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
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")
query = New ObjectQuery("SELECT * FROM Win32_Account")
searcher = New ManagementObjectSearcher(scope, query)
queryCollection = searcher.Get()
For Each m As ManagementObject In queryCollection
strAccount = (m.Item("Name"))
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)
2009-05-24 10:31:47,969  ERROR [app(TaskRunnerAccountDiscovery.exe) class(TaskRunnerAccountDiscovery) method(EnumerateLocalAccounts) line(203)] - Error occurred: The remote procedure call failed.
2009-05-24 10:34:39,508  ERROR [app(TaskRunnerAccountDiscovery.exe) class(TaskRunnerAccountDiscovery) method(Main) line(119)] - Error: Object reference not set to an instance of an object.