本文介绍了使用WMI在x64平台上的C#中检索防病毒产品信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

这实际上是我的第一篇文章,并且是C#.NET编程的新手.我一直在遍及MSDN和Internet,但是找不到答案.

我正在编写一个小程序,向用户显示有关Windows 7或Vista x64计算机上安装的防病毒信息.

我正在尝试检测我自己的计算机上的"Kaspersky Internet Security".(Windows 7 x64).kaspersky是在防病毒软件,Internet安全和反间谍软件中注册的WMI.

我找到了此帖子- http://social. msdn.microsoft.com/Forums/zh-CN/csharpgeneral/thread/d555f390-dd75-4604-b653-df0a9f4c2fa3/
但它不适用于x64.看来在Windows x64版本或其他版本中," root \ security "的路径是不同的.

以下代码适用于32位Windows XP,但不适用于7 x64.

有什么主意吗?

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;
    }  
  }
}

推荐答案




这篇关于使用WMI在x64平台上的C#中检索防病毒产品信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 09:12