0

I use following way to get file version of Control Panel.

var searcher = new System.Management.ManagementObjectSearcher(
  "SELECT * FROM Win32_Product where Name ='My Application'");
foreach (System.Management.ManagementObject obj in searcher.Get())
{
    MessageBox.Show("Latest Verstion: " + obj["Version"].toString());
}

This takes around 10 seconds to find the version. Can anybody suggest me faster way to get file version of Control Panel file?

Note: If I change query SELECT Version FROM Win32_Product where Name ='My Application', it takes same time.

Nanji Mange
  • 2,155
  • 4
  • 29
  • 63
  • Don't use `select *` – stuartd Oct 03 '16 at 08:58
  • @stuartd can you please give me example? Do you mean `Select Version FROM Win32_Product where Name ='My Application'`? – Nanji Mange Oct 03 '16 at 09:08
  • Yes, exactly that - the more properties you retrieve, the more work WMI has to do and the longer it takes. – stuartd Oct 03 '16 at 09:13
  • Note there are also [issues with Win32_Product](https://support.microsoft.com/en-us/kb/974524) and [known slowness](http://stackoverflow.com/questions/208355/why-is-enumerating-installed-msi-packages-so-slow) is one of them, that question has lots of other approaches you can use. – stuartd Oct 03 '16 at 09:15
  • @stuartd I think the link you have given me is for VBScript. I need the information in C# for my windows based application. Please suggest. – Nanji Mange Oct 03 '16 at 12:55
  • Makes no difference whether you use C# or VBA or whatever, if you query `Win32_Product` it's going to be slow because of the Consistency Check. – stuartd Oct 03 '16 at 13:18

0 Answers0