ManagementObjectSearcher throwing "Not Found" exception for mandatory property

1k views Asked by At

I am using the following code without problem in 99% of machines...

var ms = new ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem");
return (ms.Get()
    .Cast<ManagementBaseObject>()
    .Select(o => o["Model"])
    .Cast<string>()
    .Select(s => vmModels.Trim()
         .Split(',').Contains(s, StringComparer.OrdinalIgnoreCase))).FirstOrDefault();

However, on a small set of machines, this is throwing a "Not Found" exception:

System.Management.ManagementException: Not found 
   at System.Management.ThreadDispatch.Start()
   at System.Management.ManagementScope.Initialize()
   at System.Management.ManagementObjectSearcher.Initialize()
   at System.Management.ManagementObjectSearcher.Get()
   ....

All machines are running identical images in a Virtual environment. The code is intended to determine whether the machines are running in a VM or not by utilizing the Model property to determine the Model name of the VM.

I'm unsure if the problem is transient or persistent, as I haven't been able to recreate it myself, and am only seeing the reports from users.

OS is Windows 7 SP1, and according to the documentation, the Model property is mandatory:

http://msdn.microsoft.com/en-us/library/aa394102(v=vs.85).aspx

Model
    Data type: string
    Access type: Read-only

    Product name that a manufacturer gives to a computer. 
    **This property must have a value.**

I'm at a loss on how to deal with this. I need to know the value of this property, so merely catching the exception doesn't help.

Are there any known issues with WMI intermittently not working? Why would a mandatory property not be available?

Any suggestions on a more reliable way to find this information?

EDIT:

One other aspect, I discovered this only seems to happen when the apps are packaged with VMware ThinApp. It works fine, even with ThinApp on most machines, but the non-thinapped version works correctly on the machines that the Thinapped version fails on.

0

There are 0 answers