scott oliver

scott oliver

  • NA
  • 82
  • 16.2k

Need help with visual studio 2008

Dec 9 2014 6:15 PM
Need help with an old version of visual studio. I am using visual studio express 2008 because of the version of .net i am working with. I am using the below code and it throws me an exception. Seems pretty straight forward but im stumped can any one help? 
 
it throws a issue at the foreach on the "in" saying its an invalid class. havnt seen this one before. 
 
 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
using System.Data;
using System.Threading;
using System.Management;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
ManagementObjectSearcher mos = new ManagementObjectSearcher("SELECT * FROM Win32_Product WHERE Name = '" + "Symantec Endpoint Protection" + "'");
foreach (ManagementObject mo in mos.Get())
{
try
{
if (mo["Name"].ToString() == "Symantec Endpoint Protection")
{
object hr = mo.InvokeMethod("Uninstall", null);
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
//this program may not have a name property, so an exception will be thrown
}
try
{
if (mo["Name"].ToString() == "Symantec Endpoint Protection Manager")
{
object hr = mo.InvokeMethod("Uninstall", null);
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
//this program may not have a name property, so an exception will be thrown
}
}
}
}
}
 

Answers (2)