Missing directive or assembly reference using WMI ManagementObjectSearcher?

ぐ巨炮叔叔 提交于 2019-11-30 04:07:29

问题


I have found this link:

Detect Antivirus on Windows using C#

However when I try this code in visual c# express edition 2008 it says :

Error 1 The type or namespace name 'ManagementObjectSearcher' could not be found 
(are you missing a using directive or an assembly reference?) 
C:\Users\Andy\Documents\Visual Studio 2008\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs 15 17 ConsoleApplication1

Amongst other similar errors on the 2 lines which seem important!

Looks like the code segment is missing some imports or something?

I am using Windows 7... Please help!

Andy


回答1:


You are missing a reference to the assembly containing the type ManagementObjectSearcher, which is in the System.Managementnamespace. Add this namespace and it should work.

You will have to rightclick the project -> add reference and add the System.Management assembly. System.Managment is not added automatically with the creation of a new project.

WMI reference
WMI + C#



来源:https://stackoverflow.com/questions/3692384/missing-directive-or-assembly-reference-using-wmi-managementobjectsearcher

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!