0

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)
                        Try
                            scope.Connect()
                            Dim query As New ObjectQuery("SELECT * FROM Win32_ComputerSystem")
                            Dim searcher As New ManagementObjectSearcher(scope, query)
                            Try
                                For Each queryObj As ManagementObject In searcher.Get()
                                    Dim usnm As String = queryObj("UserName")
                                                                    Next

                            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
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Oxiegen
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.