8

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

Community
  • 1
  • 1
RenegadeAndy
  • 5,440
  • 18
  • 70
  • 130

1 Answers1

26

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#

Femaref
  • 60,705
  • 7
  • 138
  • 176
  • That is actually in the code see this pastebin to see exactly what I have :http://pastebin.com/y7s76Uf4 – RenegadeAndy Sep 11 '10 at 20:03
  • 1
    You have to add a reference to the project itself. see my edit. – Femaref Sep 11 '10 at 20:14
  • Great it runs now - however it reckons i have no antivirus software installed, I am running Windows 7 - presume it is not supported. Do you know what would need to be changed in order to have it detect under windows 7? – RenegadeAndy Sep 11 '10 at 20:17
  • Was able to sort it out actually by changing a line slightly : @"\root\SecurityCenter2" - do you know where the documentation is for WMI? and using it with c#?! – RenegadeAndy Sep 11 '10 at 22:22
  • added two links in the post, but you should try and google yourself (just type `msdn searchphrase` and it will usually only find msdn entries, I searched for `msdn WMI` and `msdn WMI C#` respectively). – Femaref Sep 12 '10 at 01:30
  • Thank you.I am struggling to find the information I need though - i am trying to get the property names for antivirusproduct but I cannot find them in the documentation? – RenegadeAndy Sep 12 '10 at 13:39
  • I can't really help you with that, I would have to search myself. If you need further help, please ask another question. – Femaref Sep 12 '10 at 13:48