MapInfo version detection.

I thought I would just write a follow up post for my creating an instance of MapInfo COM object series about being able to detect which version of MapInfo the user has installed.

In this blog post I’m going to show some sample code that you can use to find which version/s of MapInfo the user has installed, to allow you to notify which version of MapInfo your application is compatible with.

When you install MapInfo, it creates a key in the registry which stores information for MapInfo like MI version,COM GUID, Access code etc. The key that contains this information is located in:


if we open up the registry and have a look at that key we should be able to see something that looks like this:







In the above picture you can see that professional subkey shows a folder for each version of MapInfo that you have installed, as you can see on my PC I have version 9.5 and 10 installed.  Each one of these keys holds the information for that installed version of MapInfo, if we have a look at the information of version 10 it looks something like this:










As you can see the key has all the information about the installed version 10 of MapInfo including Access Code(000000 for demo version),the COM GUID for MapInfo and install path.

Enough talk lets see some code:

This is a little bit of C#3.0 sample code that you can use to detect and display which version of MapInfo the version has installed.

   1: string registryKey = @"SOFTWARE\MapInfo\MapInfo\Professional";
   3: using (Microsoft.Win32.RegistryKey prokey = Registry.LocalMachine.OpenSubKey(registryKey))
   4: {
   5:     var versions = from a in prokey.GetSubKeyNames()
   6:                    let r = prokey.OpenSubKey(a)
   7:                    let name = r.Name
   8:                    let slashindex = name.LastIndexOf(@"\")
   9:                    select new
  10:                    {
  11:                       MapinfoVersion = Convert.ToInt32(name.Substring(slashindex + 1,
  12:                                                                        name.Length - slashindex -1))
  13:                    };
  15:     Console.WriteLine("Installed Mapinfo Version");
  16:     foreach (var item in versions)
  17:     {
  18:         Console.WriteLine("Mapinfo Version: {0}", item.MapinfoVersion);
  19:     }
  20: }

If you don’t want to use LINQ you could use something like this:

   1: string registryKey = @"SOFTWARE\MapInfo\MapInfo\Professional";
   3: using (Microsoft.Win32.RegistryKey prokey = Registry.LocalMachine.OpenSubKey(registryKey))
   4: {
   5:     List<int> versions = new List<int>();
   6:     foreach (string key in prokey.GetSubKeyNames())
   7:     {
   8:         RegistryKey subkey = prokey.OpenSubKey(key);
   9:         string name = subkey.Name;
  10:         int slashindex = name.LastIndexOf(@"\");
  11:         int version = Convert.ToInt32(name.Substring(slashindex + 1,
  12:                                                      name.Length - slashindex - 1));
  13:         versions.Add(version);
  14:     }
  16:     Console.WriteLine("Installed Mapinfo Version");
  17:     foreach (int mapinfoversion in versions)
  18:     {
  19:         Console.WriteLine("Mapinfo Version: {0}", mapinfoversion);

20: }

Both will output the installed versions to the console:


Now detecting the version is all well and good but you really need to tell the user if they won’t be able to use your application if they are running a version lower then your application was built with.

Something like this would do it:

   1: const int NeededMapinfoVersion = 1000;
   3: Console.WriteLine("Checking Mapinfo Version");
   4: foreach (var item in versions)
   5: {
   6:     if (item.MapinfoVersion < NeededMapinfoVersion)
   7:     {
   8:         Console.WriteLine("Sorry I need Mapinfo Version {0} but you have {1}",
   9:                           NeededMapinfoVersion,item.MapinfoVersion);
  10:        // Exit the app.
  11:     }
  12:     else
  13:     {
  14:         Console.WriteLine("Your good to go");
  15:         break;
  16:     }
  17: }

Of course the above code is pretty rough but it should do the trick.

Hope this helps.

2 thoughts on “MapInfo version detection.

  1. Is there a way to tell what version of MapInfo Pro is currently running, if a user has two versions installed?

    I’m hoping that there a system/environmental variable that points to the specific mapinfow.exe path that is currently being used.

    1. You are talking about having two versions installed but only wanting to be able to see which version is currently running.

      I’m not aware of any environmental variable that will help you but you could get the processes by name and get their file version like this:

      foreach (var item in Process.GetProcessesByName(“MapInfow”))

      This should give you the file version of the running instances of MapInfo.

      Don’t know if this helps you.

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s