ManagementObjectSearcher is not defined even after adding the System.Management link in the VB2005 project

I have the following code in the code file for the .aspx page in the project:

Dim searcher As New ManagementObjectSearcher("SELECT RemoteName FROM win32_NetworkConnection WHERE LocalName = '" & sFilePath.Substring(0, 2) & "'") For Each managementObject As ManagementObject In searcher.[Get]() Dim sRemoteName As String = TryCast(managementObject("RemoteName"), String) sRemoteName += sFilePath.Substring(2) Return (New Uri(sRemoteName)).ToString() Next Return sFilePath 

The ManagementObjectSearcher and ManagementObject elements are underlined and say they are undefined.

I added the System.Management link, deleted and read, deleted my cache, rebuilt the entire .aspx page, deleted the .dll and many other troubleshooting tips that I found on Google, but still cannot find the answer to this problem.

Please, help!

+4
source share
3 answers

At the top of the project, add to the namespace, as usual:

 Imports System.Management 

Then in the project menu at the top (in Visual Studio) select "Add Link ...". On the .Net tab, scroll down to System.Management. Select this line and click OK.

+10
source

Add Imports System.Management to the top of the .vb file so you can use the class without specifying its namespace .

0
source

Before adding β€œImport” to your class, you must first add the link (in the DLL) to your project.

0
source

All Articles