Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Hello,

This is actually my first post and I'm new to C#.NET programing. I have been looking all over MSDN and the internet, but couldn't find the answer.

I'm writing a small program to show the user the information regarding the anti-virus installed on his Windows 7 or Vista x64 machine.

I'm trying to detect "Kaspersky internet security" which is on my own machine.(Windows 7 x64).kaspersky is WMI registered in both antivirus and internet security and antispy.

I found this post - http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/d555f390-dd75-4604-b653-df0a9f4c2fa3/,
but it didn't work for x64. It looks that the path to "root\security" is different in x64 version of Windows or something.

The following code works for Windows XP 32-bit but not for 7 x64.

Any idea?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Management;

namespace WindowsFormsApplication1
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
      label1.Text = "Company =" + Antivirus("companyName");
      label2.Text = "Name =" + Antivirus("displayName");
    }
    private string Antivirus(string type)
    {
      string computer = Environment.MachineName;
      string wmipath = @"\\" + computer + @"\root\SecurityCenter";
      try
      {
        ManagementObjectSearcher searcher = new ManagementObjectSearcher(wmipath,
          "SELECT * FROM AntivirusProduct");
        ManagementObjectCollection instances = searcher.Get();
        //MessageBox.Show(instances.Count.ToString()); 
        foreach (ManagementObject queryObj in instances)
        {
          return queryObj[type].ToString();
        }
      }

      catch (Exception e)
      {
        MessageBox.Show(e.Message);
      }

      return null;
    }  
  }
}
Posted
Updated 25-Aug-10 8:15am
v2
Comments
priyanmuthu 3-Oct-16 3:07am    
Also How do i find whether the anti-virus is up-to-date?

string wmipathstr = @"\\" + Environment.MachineName + @"\root\SecurityCenter2";

it works on my win 7

:)
 
Share this answer
 
Windows 7 is where I tried to get some result.

From what I have been searching for, it looks Windows Vista/7 doesn't support that kind of query anymore.

The code still works under XP.
 
Share this answer
 
v2
Yes, that worked! Thanks a lot, man.
So it looks you just have to put securitycenter2 instead of securitycenter and everything works fine.
 
Share this answer
 
v2
Hi all,

Even i got stuck here with 'invalid namespace' error.
my code fetches the details of the current environment but when i try to fetch anti virus updates of the remote server it throws an exception: invalid namespace
please help(all the servers run windows xp)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900