天天看點

C#+ArcEngine代碼檢測ArcEngine Runtime是否安裝以及是否授權



C#+ArcEngine代碼檢測ArcEngine是否安裝以及是否授權

檢測ArcEngine Runtime是否安裝的代碼

       private void CheckInStallAERuntime()

        {

            //通過查詢系統系統資料庫檢測是否安裝

            Microsoft.Win32.RegistryKey LocalMachineRegKey = Microsoft.Win32.Registry.LocalMachine;

            Microsoft.Win32.RegistryKey InstallDirRegKey = LocalMachineRegKey.OpenSubKey(@"SOFTWARE\ESRI\Engine10.0\CoreRuntime");

            if (InstallDirRegKey == null)

            {

                MessageBox.Show("沒有安裝ArcGIS Runtime!");

            }

            else

            {

                string InstallDirStr = InstallDirRegKey.GetValue("InstallDir").ToString();

                MessageBox.Show("ArcGIS Runtime安裝目錄:" + InstallDirStr);

            }

        }

檢測ArcEngine Runtime是否授權的代碼

        private bool CheckLicenseProduct()

        {

            //Check out a Spatial Analyst license with the ArcView product.

            esriLicenseProductCode productCode = esriLicenseProductCode.esriLicenseProductCodeEngine;

            IAoInitialize pAoInitialize = new AoInitializeClass();

            esriLicenseStatus licenseStatus = esriLicenseStatus.esriLicenseUnavailable;

            //Check the productCode.

            licenseStatus = pAoInitialize.IsProductCodeAvailable(productCode);

            if (licenseStatus == esriLicenseStatus.esriLicenseAvailable)

            {

                pAoInitialize = null;

                return true;

            }

            return false;       

        }

在判斷runtime是否授權之前必須進行許可綁定,否則出錯