c#查詢部署機器的Office應用程式的版本

來源:互聯網
上載者:User

檢測office的應用程式的版本,

public class OfficeVersion    {        /// <summary>        /// 擷取Access的提供者        /// </summary>        /// <returns>是否設定成功</returns>        public static string GetAccessProvider()        {            //檢測客戶機器上安裝的Access版本2000/2003/2007/2010            string version = OfficeVersion.GetAppVersion("Access");            string provider = string.Empty;            switch (version)            {                case "Access 2007":                case "Access 2010":                    provider = "Microsoft.ACE.OLEDB.12.0";                    break;                case "Access 2000":                case "Access xp":                case "Access 2003":                    //default:                    provider = "Microsoft.Jet.OLEDB.4.0";                    break;            }            return provider;        }        //檢測客戶機器上安裝的應用程式版本2000/2003/2007/2010        public static string GetAppVersion(string officeAppName)        {            string result = string.Empty;            RegistryOperate registry = new RegistryOperate("LOCAL_MACHINE");            string[] officeKey = registry.GetAllSubKey(@"SOFTWARE\\Microsoft\\Office\\");            List<string> listOfficeKey = new List<string>(officeKey);            if (listOfficeKey.Count < 1)            {                return "No Office";            }            if (listOfficeKey.Contains("14.0"))//Office 2010            {                string[] keyItem = registry.GetAllSubKey(@"SOFTWARE\\Microsoft\\Office\\14.0");                List<string> subKeyItem = new List<string>(keyItem);                if (IsExistSubKey(@"SOFTWARE\\Microsoft\\Office\\14.0", officeAppName))                {                    result = string.Format("{0} 2010", officeAppName);                }            }            if (result.Equals("") && listOfficeKey.Contains("12.0"))//Office 2007            {                string[] keyItem = registry.GetAllSubKey(@"SOFTWARE\\Microsoft\\Office\\12.0");                List<string> subKeyItem = new List<string>(keyItem);                if (IsExistSubKey(@"SOFTWARE\\Microsoft\\Office\\12.0", officeAppName))                {                    result = string.Format("{0} 2007", officeAppName);                }            }            if (result.Equals("") && listOfficeKey.Contains("11.0"))//Office 2003            {                string[] keyItem = registry.GetAllSubKey(@"SOFTWARE\\Microsoft\\Office\\11.0");                List<string> subKeyItem = new List<string>(keyItem);                if (IsExistSubKey(@"SOFTWARE\\Microsoft\\Office\\11.0", officeAppName))                {                    result = string.Format("{0} 2003", officeAppName);                }            }            if (result.Equals("") && listOfficeKey.Contains("10.0"))//Office xp            {                string[] keyItem = registry.GetAllSubKey(@"SOFTWARE\\Microsoft\\Office\\10.0");                List<string> subKeyItem = new List<string>(keyItem);                if (IsExistSubKey(@"SOFTWARE\\Microsoft\\Office\\10.0", officeAppName))                {                    result = string.Format("{0} xp", officeAppName);                }            }            if (result.Equals("") && listOfficeKey.Contains("9.0"))//Office 2000            {                string[] keyItem = registry.GetAllSubKey(@"SOFTWARE\\Microsoft\\Office\\9.0");                List<string> subKeyItem = new List<string>(keyItem);                if (IsExistSubKey(@"SOFTWARE\\Microsoft\\Office\\9.0", officeAppName))                {                    result = string.Format("{0} 2000", officeAppName);                }            }            return result;        }        /// <summary>        /// 判斷註冊表路徑是否存在子項        /// </summary>        /// <param name="path">註冊表路徑</param>        /// <param name="value">子項名</param>        /// <returns></returns>        private static bool IsExistSubKey(string path, string key)        {            RegistryOperate registry = new RegistryOperate("LOCAL_MACHINE");            string[] keyItem = registry.GetAllSubKey(path);            List<string> listKeyItem = new List<string>(keyItem);            if (listKeyItem.Contains(key))            {                return true;            }            return false;        }    }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.