9

Is there a way using ArcObjects.net to find out what version of ArcGIS is installed on a machine (i.e. 9.3., 10.0, 10.1)?

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jan 16, 2013 at 23:56
1
  • or even a registry location would be helpful. I just need a way for the program to figure out what version of ArcGIS the user has installed. File paths won't work because ArcGIS doesn't seem to uninstall the old folders in the AppData folder Commented Jan 17, 2013 at 0:01

4 Answers 4

8

In ArcObjects .NET, use the RuntimeManager e.g.:

Listing all installed runtimes:

var runtimes = RuntimeManager.InstalledRuntimes;
foreach (RuntimeInfo runtime in runtimes)
{
 System.Diagnostics.Debug.Print(runtime.Path);
 System.Diagnostics.Debug.Print(runtime.Version);
 System.Diagnostics.Debug.Print(runtime.Product.ToString());
}

or, to just get the currently active runtime:

bool succeeded = ESRI.ArcGIS.RuntimeManager.Bind(ProductCode.EngineOrDesktop);
if (succeeded)
{
 RuntimeInfo activeRunTimeInfo = RuntimeManager.ActiveRuntime;
 System.Diagnostics.Debug.Print(activeRunTimeInfo.Product.ToString());
}

Also in arcpy, you can use GetInstallInfo.

answered Jan 17, 2013 at 0:24
4
  • Reason for downvote? Commented Jan 17, 2013 at 0:55
  • I gave +1 so was surprised to see 0 when I looked back just now too - I also liked your ArcPy reminder. Commented Jan 17, 2013 at 1:08
  • IIRC RuntimeManager was introduced with ArcGIS 10.0, and therefore cannot be used to detect earlier ArcGIS versions. Commented Aug 4, 2015 at 12:24
  • Same goes for ArcPy -- that did not exist yet in versions prior to 10.0. Commented Aug 4, 2015 at 12:36
3

On a Win7 64 bit PC this Registry Key may help. I have 10.0 installed, and it reads 10.0.2414.

\HKLM\software\wow6432Node\esri\Arcgis\RealVersion

answered Jan 17, 2013 at 0:21
6
  • 1
    This one is useful for when ArcObjects is unavailable, I use when building installers. Commented Jan 17, 2013 at 0:32
  • 2
    On 32-bit this key is HKLM\SOFTWARE\ESRI\ArcGIS\RealVersion Commented Jan 17, 2013 at 0:57
  • @mwalker Also on 64 bit with 10.1 I see HKLM\SOFTWARE\ESRI\ArcGIS\RealVersion, I wonder if this key exists at 10.0? Commented Jan 17, 2013 at 4:13
  • @Kirk, I do not have that key on 64-bit at 10.1 -- wonder why not. Commented Jan 17, 2013 at 4:23
  • @blah238 I've got 10.1 sp1, both desktop and server installed. Not sure which installation created the key. Commented Jan 17, 2013 at 5:03
1

There seems to be an interface called IArcGISVersion with a getVersions method which may be what you need.

UPDATE

Above relates to Java (thanks @blah238) - here is link to .NET (thanks @JasonScheirer)

answered Jan 17, 2013 at 0:13
2
  • That is for Java only. Commented Jan 17, 2013 at 0:16
  • 1
    Link to the .Net version. Commented Jan 17, 2013 at 0:17
0

You can also get the ArcGIS version by querying the version of AfCore.dll. This requires knowing the ArcGIS install directory, which you can either get by querying the registry or by hardcoding (it's C:\Program Files (x86)\ArcGIS\Desktop10.3\ for most users).

/// <summary>
/// Find the version of the currently installed ArcGIS Desktop
/// </summary>
/// <returns>Version as a string in the format x.x or empty string if not found</returns>
internal string GetArcGISVersion()
{
 try
 {
 FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(Path.Combine(Path.Combine(GetInstallDir(), "bin"), "AfCore.dll"));
 return string.Format("{0}.{1}", fvi.FileMajorPart, fvi.FileMinorPart);
 }
 catch (FileNotFoundException ex)
 {
 Console.WriteLine(string.Format("Could not get ArcGIS version: {0}. {1}", ex.Message, ex.StackTrace));
 }
 return "";
}
/// <summary>
/// Look in the registry to find the install directory of ArcGIS Desktop.
/// Searches in reverse order, so latest version is returned.
/// </summary>
/// <returns>Dir name or empty string if not found</returns>
private string GetInstallDir()
{
 string installDir = "";
 string esriKey = @"Software\Wow6432Node\ESRI";
 foreach (string subKey in GetHKLMSubKeys(esriKey).Reverse())
 {
 if (subKey.StartsWith("Desktop"))
 {
 installDir = GetRegValue(string.Format(@"HKEY_LOCAL_MACHINE\{0}\{1}", esriKey, subKey), "InstallDir");
 if (!string.IsNullOrEmpty(installDir))
 return installDir;
 }
 }
 return "";
}
/// <summary>
/// Returns all the subkey names for a registry key in HKEY_LOCAL_MACHINE
/// </summary>
/// <param name="keyName">Subkey name (full path excluding HKLM)</param>
/// <returns>An array of strings or an empty array if the key is not found</returns>
private string[] GetHKLMSubKeys(string keyName)
{
 using (RegistryKey tempKey = Registry.LocalMachine.OpenSubKey(keyName))
 {
 if (tempKey != null)
 return tempKey.GetSubKeyNames();
 return new string[0];
 }
}
/// <summary>
/// Reads a registry key and returns the value, if found.
/// Searches both 64bit and 32bit registry keys for chosen value
/// </summary>
/// <param name="keyName">The registry key containing the value</param>
/// <param name="valueName">The name of the value</param>
/// <returns>string representation of the actual value or null if value is not found</returns>
private string GetRegValue(string keyName, string valueName)
{
 object regValue = null;
 regValue = Registry.GetValue(keyName, valueName, null);
 if (regValue != null)
 {
 return regValue.ToString();
 }
 // try again in 32bit reg
 if (keyName.Contains("HKEY_LOCAL_MACHINE"))
 regValue = Registry.GetValue(keyName.Replace(@"HKEY_LOCAL_MACHINE\Software", @"HKEY_LOCAL_MACHINE\Software\Wow6432Node"), valueName, null);
 else if (keyName.Contains("HKEY_CURRENT_USER"))
 regValue = Registry.GetValue(keyName.Replace(@"HKEY_CURRENT_USER\Software", @"HKEY_CURRENT_USER\Software\Wow6432Node"), valueName, null);
 if (regValue != null)
 {
 return regValue.ToString();
 }
 return "";
}
answered Jun 29, 2016 at 10:24

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.