Làm thế nào bạn có thể tìm thấy phiên bản ArcGIS theo chương trình?


9

Có cách nào sử dụng ArcObjects.net để tìm hiểu phiên bản ArcGIS nào được cài đặt trên máy (tức là 9.3., 10.0, 10.1) không?


hoặc thậm chí một vị trí đăng ký sẽ hữu ích. Tôi chỉ cần một cách để chương trình tìm ra phiên bản ArcGIS mà người dùng đã cài đặt. Đường dẫn tệp sẽ không hoạt động vì ArcGIS dường như không gỡ cài đặt các thư mục cũ trong thư mục AppData
Nick

Câu trả lời:


8

Trong ArcObjects .NET, sử dụng RuntimeManager, vd:

Liệt kê tất cả thời gian chạy đã cài đặt:

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());
}

hoặc, để có được thời gian chạy hiện đang hoạt động:

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

Ngoài ra trong arcpy, bạn có thể sử dụng GetInstallInfo .


Lý do cho downvote?
blah238

Tôi đã cho +1 nên rất ngạc nhiên khi thấy 0 khi tôi cũng vừa mới nhìn lại - Tôi cũng thích lời nhắc ArcPy của bạn.
PolyGeo

IIRC RuntimeManagerđược giới thiệu với ArcGIS 10.0, và do đó không thể được sử dụng để phát hiện các phiên bản ArcGIS trước đó.
stakx

Điều tương tự cũng xảy ra với ArcPy - chưa tồn tại trong các phiên bản trước 10.0.
stakx

3

Trên PC Win7 64 bit, Khóa đăng ký này có thể giúp ích. Tôi đã cài đặt 10.0 và nó đọc 10.0.2414.

\ HKLM \ phần mềm \ wow6432Node \ esri \ Arcgis \ RealVersion


1
Cái này hữu ích khi ArcObjects không có sẵn, tôi sử dụng khi xây dựng trình cài đặt.
Kelly Thomas

2
Trên 32-bit, khóa này là HKLM \ SOFTWARE \ ESRI \ ArcGIS \ RealVersion
mwalker

@mwalker Cũng trên 64 bit với 10.1 Tôi thấy HKLM \ SOFTWARE \ ESRI \ ArcGIS \ RealVersion, tôi tự hỏi liệu khóa này có tồn tại ở 10.0 không?
Kirk Kuykendall

@Kirk, tôi không có khóa đó trên 64-bit ở 10.1 - tự hỏi tại sao không.
blah238

@ blah238 Tôi đã cài đặt 10.1 sp1, cả máy tính để bàn và máy chủ. Không chắc chắn cài đặt nào tạo ra khóa.
Kirk Kuykendall


0

Bạn cũng có thể lấy phiên bản ArcGIS bằng cách truy vấn phiên bản AfCore.dll. Điều này đòi hỏi phải biết thư mục cài đặt ArcGIS, mà bạn có thể nhận được bằng cách truy vấn sổ đăng ký hoặc bằng cách mã hóa (đó là C: \ Program Files (x86) \ ArcGIS \ Desktop10.3 \ cho hầu hết người dùng).

/// <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 "";
}
Khi sử dụng trang web của chúng tôi, bạn xác nhận rằng bạn đã đọc và hiểu Chính sách cookieChính sách bảo mật của chúng tôi.
Licensed under cc by-sa 3.0 with attribution required.