help using Win32_Product.Uninstall

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve Long

    #1

    help using Win32_Product.Uninstall

    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 ManagementExcep tion of
    Invalid class:


    ManagementScope ms = new ManagementScope (@"root\cimv2") ;
    SelectQuery q = new SelectQuery("SE LECT * From Win32_Product where
    InstallState = 5");
    ManagementObjec tSearcher query = new ManagementObjec tSearcher(ms, q);
    ManagementObjec tCollection queryCollection = query.Get();

    // this line is where I'm getting the exception
    foreach(Managem entObject mo in queryCollection )
    {
    Console.WriteLi ne("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


  • Peter Bromberg [C# MVP]

    #2
    RE: help using Win32_Product.U ninstall

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


    --
    Co-founder, Eggheadcafe.com developer portal:

    UnBlog:





    "Steve Long" wrote:
    [color=blue]
    > 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 ManagementExcep tion of
    > Invalid class:
    >
    >
    > ManagementScope ms = new ManagementScope (@"root\cimv2") ;
    > SelectQuery q = new SelectQuery("SE LECT * From Win32_Product where
    > InstallState = 5");
    > ManagementObjec tSearcher query = new ManagementObjec tSearcher(ms, q);
    > ManagementObjec tCollection queryCollection = query.Get();
    >
    > // this line is where I'm getting the exception
    > foreach(Managem entObject mo in queryCollection )
    > {
    > Console.WriteLi ne("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
    >
    >
    >[/color]

    Comment

    • Steve Long

      #3
      Re: help using Win32_Product.U ninstall

      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]" <pbromberg@yaho o.nospammin.com > wrote in message
      news:15AF0264-CDCD-4F01-BB02-87EDF05206A0@mi crosoft.com...[color=blue]
      > 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:
      >[color=green]
      > > Hello,
      > > can someone help me figure out how to do a couple of things here? I[/color][/color]
      would[color=blue][color=green]
      > > like to use the Uninstall method of the Win32_Product class and am[/color][/color]
      having[color=blue][color=green]
      > > trouble figuring this one out.
      > > When I do a query with the following code, I get a ManagementExcep tion[/color][/color]
      of[color=blue][color=green]
      > > Invalid class:
      > >
      > >
      > > ManagementScope ms = new ManagementScope (@"root\cimv2") ;
      > > SelectQuery q = new SelectQuery("SE LECT * From Win32_Product where
      > > InstallState = 5");
      > > ManagementObjec tSearcher query = new ManagementObjec tSearcher(ms, q);
      > > ManagementObjec tCollection queryCollection = query.Get();
      > >
      > > // this line is where I'm getting the exception
      > > foreach(Managem entObject mo in queryCollection )
      > > {
      > > Console.WriteLi ne("Name: " + mo["Name"].ToString());
      > > // how do I invoke the Uninstall method here (given my condition is[/color][/color]
      met[color=blue][color=green]
      > > of course)?
      > > }
      > >
      > >
      > > P.S. sorry if this is totally hosed code and I appreciate any help on[/color][/color]
      it.[color=blue][color=green]
      > > Thanks
      > > Steve
      > >
      > >
      > >[/color][/color]


      Comment

      • Peter Bromberg [C# MVP]

        #4
        Re: help using Win32_Product.U ninstall

        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:

        UnBlog:





        "Steve Long" wrote:
        [color=blue]
        > 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]" <pbromberg@yaho o.nospammin.com > wrote in message
        > news:15AF0264-CDCD-4F01-BB02-87EDF05206A0@mi crosoft.com...[color=green]
        > > 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:
        > >[color=darkred]
        > > > Hello,
        > > > can someone help me figure out how to do a couple of things here? I[/color][/color]
        > would[color=green][color=darkred]
        > > > like to use the Uninstall method of the Win32_Product class and am[/color][/color]
        > having[color=green][color=darkred]
        > > > trouble figuring this one out.
        > > > When I do a query with the following code, I get a ManagementExcep tion[/color][/color]
        > of[color=green][color=darkred]
        > > > Invalid class:
        > > >
        > > >
        > > > ManagementScope ms = new ManagementScope (@"root\cimv2") ;
        > > > SelectQuery q = new SelectQuery("SE LECT * From Win32_Product where
        > > > InstallState = 5");
        > > > ManagementObjec tSearcher query = new ManagementObjec tSearcher(ms, q);
        > > > ManagementObjec tCollection queryCollection = query.Get();
        > > >
        > > > // this line is where I'm getting the exception
        > > > foreach(Managem entObject mo in queryCollection )
        > > > {
        > > > Console.WriteLi ne("Name: " + mo["Name"].ToString());
        > > > // how do I invoke the Uninstall method here (given my condition is[/color][/color]
        > met[color=green][color=darkred]
        > > > of course)?
        > > > }
        > > >
        > > >
        > > > P.S. sorry if this is totally hosed code and I appreciate any help on[/color][/color]
        > it.[color=green][color=darkred]
        > > > Thanks
        > > > Steve
        > > >
        > > >
        > > >[/color][/color]
        >
        >
        >[/color]

        Comment

        Working...