Question Connecting to Remote Computer and UnauthorizedAccessException problem

tukmolins

Member
Joined
Oct 21, 2011
Messages
12
Programming Experience
1-3
Hello and thank you for reading my thread guys and girls. I am making a client/server project where the server can send a String variable to client but for now i'm starting with a simpler code. I was able to code a bit but now i'm having a problem with this UnauthorizedAccessException. It seems that I am not authenticated but i was able to put the admin username and its password. This is my problem.. Can anyone help me with this? Thank you in advance :D

Here's my code...

Imports System
Imports System.Management.ManagementScope
Imports System.Management.Instrumentation
Imports System.Management
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
Dim options As ConnectionOptions = New ConnectionOptions()
options.Username = "myUsername"
options.Password = "myPassword"
Dim theScope As New System.Management.ManagementScope("\\192.168.2.101\root\cimv2", options)
Dim theQuery As New System.Management.ObjectQuery("SELECT * FROM Win32_Account")


Dim theSearcher As New ManagementObjectSearcher(theScope, theQuery)
Dim theCollectionOfResults As ManagementObjectCollection = theSearcher.Get()


For Each currentResult As ManagementObject In theCollectionOfResults
MessageBox.Show(currentResult("Name").ToString())
Next
Catch ex As UnauthorizedAccessException
MessageBox.Show(ex.ToString)




End Try
End Sub
End Class



Ps. I'm using Win7
 
I was able to follow all the troubleshoot instructions but it is still not working. Is it my OS or my codes? Thank you!

PS. I'm not on any Domain. I'm just using a router with dynamic IP
 
I can't see anything wrong with the code, normally code examples call ManagementScope.Connect before getting the search results, but documentation says that is not necessary.
Either it is OS configuration, firewall configuration, or router configuration.
Since 192.168.2.101 is a local network address you must have multiple computers connected to the router locally. If everything is configured correctly in OS, and all possible firewalls between the two computers allow the traffic, it must be down to router configuration.
 
I have to add, the task for a router is to route traffic between two different networks, for example local network with ISP network (that provides internet access). The traffic between computers in a local network is handled by a hub or switch. Typically a router today is actually a router-switch that has both these networking devices in one box. Network switches generally has no configuration, they just relay traffic from one computer to the others within the network. It would be weird if your router that has DHCP functionality (serving IP addresses to local computers) also didn't have switching capabilities, and that it would prevent communication between connected computers.
 
I'm wondering if WMI can be used to shutdown remote computers. If it can, can you pls help me with this? Thank you so much for the replies you've posted. At the moment i'm still reading about it but i will post something if i find anything to make it work.
 
Generally anything you can do on local computer with WMI can be done on remote computer given permission, it is just a different scope.
About WMI and shutdown I didn't know, but when searching the web for "WMI shutdown" I was repeatedly told that Win32_OperatingSystem class has shutdown methods - so know I know, until I forget.
 
Back
Top