By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,876 Members | 1,239 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,876 IT Pros & Developers. It's quick & easy.

help using Win32_Product.Uninstall

P: n/a
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
Jan 20 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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" wrote:
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

Jan 20 '06 #2

P: n/a
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 [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:15**********************************@microsof t.com...
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" wrote:
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

Jan 20 '06 #3

P: n/a
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" wrote:
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 [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:15**********************************@microsof t.com...
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" wrote:
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


Jan 20 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.