Click here to Skip to main content
15,905,566 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

the WMI code I am using fetches the anti virus updates from the
machine I am running on but while trying to fetch anti virus updates of the remote server it throws an exception: invalid namespace.
Please help
Posted

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.
 
Share this answer
 
Hi Dave,
my code goes like this:

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


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.
 
Share this answer
 
v2

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