help using Win32_Product.Uninstall

  • Thread starter Thread starter Steve Long
  • Start date Start date
S

Steve Long

Hello,
can someone help me figure out how to do a couple of things here? I would
like to use the Uninstall method of the Win32_Product class and am having
trouble figuring this one out.
When I do a query with the following code, I get a ManagementException of
Invalid class:


ManagementScope ms = new ManagementScope(@"root\cimv2");
SelectQuery q = new SelectQuery("SELECT * From Win32_Product where
InstallState = 5");
ManagementObjectSearcher query = new ManagementObjectSearcher(ms, q);
ManagementObjectCollection queryCollection = query.Get();

// this line is where I'm getting the exception
foreach(ManagementObject mo in queryCollection)
{
Console.WriteLine("Name: " + mo["Name"].ToString());
// how do I invoke the Uninstall method here (given my condition is met
of course)?
}


P.S. sorry if this is totally hosed code and I appreciate any help on it.
Thanks
Steve
 
You could also run
MSIEXEC /x package options
to uninstall, using the Process class.
Peter
 
Yea, we've considered that but the tech doesn't want to use that methodology
for some reason. Besides, isn't the classid going to change for different
versions?


Peter Bromberg said:
You could also run
MSIEXEC /x package options
to uninstall, using the Process class.
Peter


--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Steve Long said:
Hello,
can someone help me figure out how to do a couple of things here? I would
like to use the Uninstall method of the Win32_Product class and am having
trouble figuring this one out.
When I do a query with the following code, I get a ManagementException of
Invalid class:


ManagementScope ms = new ManagementScope(@"root\cimv2");
SelectQuery q = new SelectQuery("SELECT * From Win32_Product where
InstallState = 5");
ManagementObjectSearcher query = new ManagementObjectSearcher(ms, q);
ManagementObjectCollection queryCollection = query.Get();

// this line is where I'm getting the exception
foreach(ManagementObject mo in queryCollection)
{
Console.WriteLine("Name: " + mo["Name"].ToString());
// how do I invoke the Uninstall method here (given my condition is met
of course)?
}


P.S. sorry if this is totally hosed code and I appreciate any help on it.
Thanks
Steve
 
The CLSID will change, but you should still be able to enumerate them against
application names. Just trying to look at it from another angle, since I
have no idea how to manipulate the MO to "uninstall".
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Steve Long said:
Yea, we've considered that but the tech doesn't want to use that methodology
for some reason. Besides, isn't the classid going to change for different
versions?


Peter Bromberg said:
You could also run
MSIEXEC /x package options
to uninstall, using the Process class.
Peter


--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Steve Long said:
Hello,
can someone help me figure out how to do a couple of things here? I would
like to use the Uninstall method of the Win32_Product class and am having
trouble figuring this one out.
When I do a query with the following code, I get a ManagementException of
Invalid class:


ManagementScope ms = new ManagementScope(@"root\cimv2");
SelectQuery q = new SelectQuery("SELECT * From Win32_Product where
InstallState = 5");
ManagementObjectSearcher query = new ManagementObjectSearcher(ms, q);
ManagementObjectCollection queryCollection = query.Get();

// this line is where I'm getting the exception
foreach(ManagementObject mo in queryCollection)
{
Console.WriteLine("Name: " + mo["Name"].ToString());
// how do I invoke the Uninstall method here (given my condition is met
of course)?
}


P.S. sorry if this is totally hosed code and I appreciate any help on it.
Thanks
Steve
 
Back
Top