0

I'm trying to collect all installed SW on each of our servers locally, and I'm using the Win32_Product WMI class for this, but on some of our servers (with Win server 2003 or 2008 R2) I can't query this class.

here is the output from PowerShell:

C:\Users\e****l> Get-WmiObject -Query "SELECT * FROM Win32_Product"
Get-WmiObject :
At line:1 char:14
+ Get-WmiObject <<<<  -Query "SELECT * FROM Win32_Product"
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

I also used this C# code that generated by WMI Code Creator (provided by Microsoft)

        try
        {
            ManagementObjectSearcher searcher =
                new ManagementObjectSearcher("root\\CIMV2",
                "SELECT * FROM Win32_Product");

            foreach (ManagementObject queryObj in searcher.Get())
            {
                Console.WriteLine("-----------------------------------");
                Console.WriteLine("Win32_Product instance");
                Console.WriteLine("-----------------------------------");
                Console.WriteLine("Name: {0}", queryObj["Name"]);
            }
        }
        catch (ManagementException e)
        {
            MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
        }

and here is the output for this:

Unhandled Exception: System.Runtime.InteropServices.COMException (0x800706BE)
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at System.Management.ManagementObjectCollection.ManagementObjectEnumerator.MoveNext()
   at WMISample.MyWMIQuery.Main()

Windows logs shows this event

enter image description here

I'll appreciate any help for that, Thanks

elady
  • 535
  • 6
  • 22
  • Is your WMI repository broken? Can you query anything in WMI on those systems? – TheMadTechnician Apr 02 '14 at 19:22
  • For example I manage to query the `Win32_OperatingSystem` class with no problem. – elady Apr 02 '14 at 19:28
  • 1
    For what it is worth, WMI repository corruption can happen on a class by class basis. So it is possible for there to be corruption in the repository but still be able to query some classes just fine. – EBGreen Apr 02 '14 at 19:29
  • 1
    It's a bad idea to use that class. Microsoft recommends against it. Just Google "win32 product is evil" – Adil Hindistan Apr 02 '14 at 19:32
  • @Adil Hindistan, So what's the best way you can suggest to list all installed SW? – elady Apr 02 '14 at 19:48
  • 1
    Most people would look at Uninstall Reg keys. There are a lot of PowerShell scripts out there to do that. – Adil Hindistan Apr 02 '14 at 20:02
  • `Win32_Product` should never be used, it is safer to [query the registry instead](https://stackoverflow.com/questions/71575378/powershell-for-software-inventory/71576041#71576041) for listing installed software inventory, and its unlikely the COMException occurring here would happen if using the technique in my linked answer above. – codewario Mar 24 '22 at 14:35

0 Answers0