help using Win32_Product.Uninstall

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
 
G

Guest

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

Steve Long

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top