I have this code that gives me the user logged on name of a remote computer, but if i run the program in certaing computers, it returns with the error "Not Available Due Restrictions" which is set if the scope cant connect...

why it connects fine in some computers and other not..is there something i have to add to the code for it to run fine in any computer

this is the code

Dim connection As New ConnectionOptions
                        connection.Username = ("ADMIN")
                        connection.Password = ("something")
                        connection.Authority = String.Format("ntlmdomain:MCMXNTEX55")
                        Dim scope As New ManagementScope("\\" & IPADDRESSH & "\root\CIMV2", connection)
                            Dim query As New ObjectQuery("SELECT * FROM Win32_ComputerSystem")
                            Dim searcher As New ManagementObjectSearcher(scope, query)
                                For Each queryObj As ManagementObject In searcher.Get()
                                    Dim usnm As String = queryObj("UserName")

                            Catch err As ManagementException
                                DataGridView1.Rows.Item(sum).Cells.Item(6).Value = "An error occurred"
                            Catch unauthorizedErr As System.UnauthorizedAccessException
                                DataGridView1.Rows.Item(sum).Cells.Item(6).Value = "Connection error"
                            End Try
                        Catch ex As Exception
                            DataGridView1.Rows.Item(sum).Cells.Item(6).Value = "Not Available Due Restrictions"
                        End Try

Why not use the My namespace? My.User.Name .
It gives the name of the currently logged on user and would save you a whole shrew of coding.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.