vb.net 即使在 VB2005 项目中添加 System.Management 引用后,也未定义 ManagementObjectSearcher
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7813715/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ManagementObjectSearcher is not defined even after adding System.Management reference in VB2005 Project
提问by user1001995
I have the following code on the code behind file for a .aspx page in a project:
我在项目中的 .aspx 页面的代码隐藏文件中有以下代码:
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.
ManagementObjectSearcher 和 ManagementObject 都带有下划线,它告诉我它们没有定义。
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.
我添加了 System.Management 引用,删除并重新读取,删除了我的缓存,重建了整个 .aspx 页面,删除了 .dll 和我在谷歌上找到的许多其他故障排除建议,但仍然找不到这个问题的答案。
Please help!
请帮忙!
回答by scrawny
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.
然后在顶部的项目菜单下(在 Visual Studio 中)选择“添加引用...”。在“.Net”选项卡下向下滚动到“System.Management”。选择该行并单击确定。
回答by Anurag Gawande
In Visual Studio > Add Reference > Assemblies > select System.Management. this way it will resolve ManagementObjectSearcher and ManagementObjects.
在 Visual Studio > 添加引用 > 程序集 > 选择 System.Management。这样它将解析 ManagementObjectSearcher 和 ManagementObjects。
回答by SLaks
回答by Aten
Before you add the "Imports" to your Class, you have first to add a Reference (to the DLL) to your Project.
在将“导入”添加到您的类之前,您必须首先向您的项目添加一个引用(到 DLL)。