更新时间:2022-12-16 23:04:06
没有看到引发异常的代码,也不知道您使用的是哪种病毒软件,就不可能告诉你怎么了.
Without seeing the code around the line that''s throwing the exception and knowing which virus software you''re using, it''s impossible to tell you what''s wrong.
戴夫,
我的代码是这样的:
Hi Dave,
my code goes like this:
private void Form1_Load(object sender, EventArgs e) {
string MName= lstMachineName.SelectedItem.ToString();
label1.Text = "Company ="+Antivirus("companyName","MName");
label2.Text = "Name =" +Antivirus("displayName", "MName");
}
private string Antivirus(string type,string MName)
{
string wmipath = @"\\" + MName@"\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;
}
该代码适用于computer.Environmenr或计算机名称为."(当前运行的计算机),但对于远程服务器计算机名称则抛出错误:无效的名称空间.
The code works fine for the computer.Environmenr or when machine name is "."(current running machine), but for remote server machine names its throwing an error:invalid namespace.