Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ManagementObjectSearcher is not defined even after adding System.Management reference in VB2005 Project

Tags:

vb.net

I have the following code on the code behind file for a .aspx page in a 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 the ManagementObject are both underlined and it is telling me that they are not defined.

I have added the System.Management reference, removed and readded, deleted my cache, rebuilt the whole .aspx page, removed the .dll and numerous other troubleshooting advise I have found on google but still cannot find the answer to this problem.

Please help!

like image 432
user1001995 Avatar asked Oct 18 '11 21:10

user1001995


3 Answers

At the top of the project add in the namespace as you would normally:

Imports System.Management

Then under the project menu at the top (in Visual Studio) select "Add Reference...". Under the ".Net" tab scroll down to "System.Management". Select that line and click OK.

like image 101
scrawny Avatar answered Oct 19 '22 01:10

scrawny


In Visual Studio > Add Reference > Assemblies > select System.Management. this way it will resolve ManagementObjectSearcher and ManagementObjects.

like image 5
Anurag Gawande Avatar answered Oct 19 '22 00:10

Anurag Gawande


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

like image 1
SLaks Avatar answered Oct 19 '22 01:10

SLaks