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();
foreach (ManagementObject queryObj in instances)
{
return queryObj[type].ToString();
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
return null;
}
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.