Checking the installed THINC API version

From time to time, I need an easy way to check the installed THINC API version on an Okuma P200 control. 

The problem is that the assembly version numbers don’t always reflect Okuma’s “official” release version number for the installation package. In fact, the Command API and Data API assemblies from the same release usually have different version numbers. 

Credit goes to Casey at Okuma for letting me know a simple way of checking the THINC API version as it’s listed on the installation package. The information is stored in the Windows registry, in the uninstall information, so just search HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall for the THINC-API entry.

Below is a quick-and-dirty C# function that searches the registry for the proper key, and returns the installed THINC API version. It can be pasted into a console application and run from a USB thumb drive, which is much more convenient than asking a client to run Regedit and search for a GUID value of “{5DFEF7ED-34FD-48E7-8104-8EBB15A1FAB4}”.

If .NET isn’t installed, then this code won’t run, but since THINC API is a .NET library, this also tells you that THINC API hasn’t been installed.

        /// <summary>Returns the installed THINC API version.
        /// </summary>
        /// <returns>The installed THINC API version, or <see langword="null"/> if not found.</returns>
        /// <remarks>
        /// Easiest way to find version is to check the Windows registry for installer information.
        /// Walk HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall. Find a key whose DisplayName is "THINC-API".
        /// When found, return the value of "DisplayVersion".
        /// GUID should be {5DFEF7ED-34FD-48E7-8104-8EBB15A1FAB4}
        /// This will throw an exception if there is any problem accessing the registry.
        /// </remarks>
        static string GetThincApiVersion()
        {
            string ret = null;
            RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", false);
            foreach(string name in key.GetSubKeyNames())
            {
                RegistryKey subkey = key.OpenSubKey(name, false);
                string displayName = (subkey.GetValue("DisplayName") ?? "").ToString();

                if (displayName == "THINC-API")
                {
                    ret = subkey.GetValue("DisplayVersion").ToString();
                    subkey.Close();
                    break;
                }

                subkey.Close();
            }
            key.Close();
            return ret;
        }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s