Question Logged On user error in Some COmputers

just369

Member
Joined
May 12, 2010
Messages
17
Programming Experience
Beginner
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



VB.NET:
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
 
Back
Top