使用WMI在x64平台上的C#中检索防病毒产品信息 [英] Retrieving Antivirus product information in C# on x64 platform using WMI
问题描述
你好,
这实际上是我的第一篇文章,并且是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;
}
}
}
推荐答案
string wmipathstr = @"\\" + Environment.MachineName + @"\ root \ SecurityCenter2";
它对我的胜利有帮助7
:)
string wmipathstr = @"\\" + Environment.MachineName + @"\root\SecurityCenter2";
it works on my win 7
:)
我尝试在Windows 7上获得一些结果.
从我一直在寻找的内容来看,Windows Vista/7似乎不再支持这种查询.
该代码仍然可以在XP下使用.
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.
是的,可以了!非常感谢,伙计.
因此,看起来您只需要放入securitycenter2
而不是securitycenter
,一切正常.
Yes, that worked! Thanks a lot, man.
So it looks you just have to putsecuritycenter2
instead ofsecuritycenter
and everything works fine.
这篇关于使用WMI在x64平台上的C#中检索防病毒产品信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!