WMI Programming with Visual Basic.NET: Breaking the Ice - Our first program to connect to WMI (on a remote computer)
(Page 4 of 4 )
The previous sections introduced you to connecting only to a local computer, i.e. your own system. But what if I wanted to get the list of drives information for another computer (within the same network)? Is it as simple as changing the "ServerName" in the WMI path? Absolutely not.
When we try to get the information from another computer, the concept of security comes in. To connect to another computer within the network, we need to provide the authentication information along with the WMI path! The following shows you the necessary modifications for the above program to connect to another computer:
Dim options As New ConnectionOptions
options.Username = "administrator"
options.Password = ""
Dim scope As New ManagementScope("\\hostname\root\cimv2", options)
Dim diskClass As New ManagementClass(scope, New ManagementPath("Win32_LogicalDisk"), Nothing)
Make sure you replace the "hostname" of the scope to the host name of the other computer within your network. So, the scope is now being provided with the necessary path, along with some connection options for username and password.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |