天天看点

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是否授权之前必须进行许可绑定,否则出错