Example #1
0
        public static string returnMinorVersion(OfficeComponent comp)
        {
            string p = GetComponentPath(comp);
            string v = GetMinorVersion(p).ToString();

            return(v);
        }
Example #2
0
        public string GetInstalledVersionOfficeAsText(OfficeComponent officeComponent)
        {
            string version = string.Empty;

            switch (GetInstalledOfficeVersion(officeComponent))
            {
            case 16: version = "MS Office 2016 - "; break;

            case 15: version = "MS Office 2013 - "; break;

            case 14: version = "MS Office 2010 - "; break;

            case 12: version = "MS Office 2007 - "; break;

            case 11: version = "MS Office 2003 - "; break;

            case 10: version = "MS Office 2002 - "; break;

            case 9: version = "MS Office 2000 - "; break;

            case 8: version = "MS Office 97 - "; break;

            case 7: version = "MS Office 95 - "; break;

            default: version = "Fant ingen office-installasjon"; break;
            }
            return(version + officeComponent.ToString());
        }
Example #3
0
        /// <summary>
        /// Istenen Office Componentinin Version İsmini Verir.
        /// Eger Component Bulunamamış ise : Return = string.Empty
        /// </summary>
        /// <param name="_component"></param>
        /// <returns>Version Number</returns>
        public static string GetVersionName(OfficeComponent _component, VersionNumberConvertName _officeVersionStock)
        {
            string versionName = string.Empty;

            if (_officeVersionStock.GetName(GetVersionNumber(_component)) != string.Empty)
            {
                versionName = _officeVersionStock.GetName(GetVersionNumber(_component));
            }

            return(versionName);
        }
Example #4
0
        private static bool CheckOfficeVersion(OfficeComponent _component, int version)
        {
            string strRegKey = @"SOFTWARE\Microsoft\Office\";

            strRegKey += version.ToString(".0").Replace(',', '.');
            strRegKey += @"\";

            switch (_component)
            {
            case OfficeComponent.Word:
                strRegKey += "Word";
                break;

            case OfficeComponent.Excel:
                strRegKey += "Excel";
                break;

            case OfficeComponent.PowerPoint:
                strRegKey += "PowerPoint";
                break;

            case OfficeComponent.Outlook:
                strRegKey += "Outlook";
                break;
            }

            strRegKey += @"\InstallRoot";

            RegistryKey r = Registry.LocalMachine.OpenSubKey(strRegKey);

            //
            if (r == null)
            {
                r = Registry.CurrentUser.OpenSubKey(strRegKey);
            }
            // check 64bit
            if (r == null)
            {
                using (var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
                {
                    r = hklm.OpenSubKey(strRegKey);
                }
            }
            if (r != null)
            {
                object val = r.GetValue("Path");
                r.Dispose();
                if (val != null)
                {
                    return(true);
                }
            }
            return(false);
        }
Example #5
0
        /// <summary>
        /// Gets the major version of the path. if file not found (or any other exception occures
        /// - returns 0
        /// </summary>
        public static int GetMajorVersion(OfficeComponent component)
        {
            string path = GetComponentPath(component);
            int toReturn = 0;
            if (File.Exists(path))
            {
                try
                {
                    var fileVersion = FileVersionInfo.GetVersionInfo(path);
                    toReturn = fileVersion.FileMajorPart;
                }
                catch
                {
                }
            }

            return toReturn; //12:2007, 11:2003, 14: 2010
        }
        private static string GetComponentPath(OfficeComponent officeComponent)
        {
            const string RegKey = @"Software\Microsoft\Windows\CurrentVersion\App Paths";
            string vl = string.Empty;
            string key = string.Empty;

            switch (officeComponent)
            {
                case OfficeComponent.Word:
                    key = "winword.exe";
                    break;
                case OfficeComponent.Excel:
                    key = "excel.exe";
                    break;
                case OfficeComponent.PowerPoint:
                    key = "powerpnt.exe";
                    break;
                case OfficeComponent.Outlook:
                    key = "outlook.exe";
                    break;
                case OfficeComponent.Access:
                    key = "msaccess.exe";
                    break;
                default:
                    break;

            }

            //looks in CURRENT_USER:
            RegistryKey mainKey = Registry.CurrentUser;
            try
            {
                mainKey = mainKey.OpenSubKey(RegKey + "\\" + key, false);
                if (mainKey != null)
                {
                    vl = mainKey.GetValue(string.Empty).ToString();
                }
            }
            catch
            { }

            //if not found, looks inside LOCAL_MACHINE:
            mainKey = Registry.LocalMachine;
            if (string.IsNullOrEmpty(vl))
            {
                try
                {
                    mainKey = mainKey.OpenSubKey(RegKey + "\\" + key, false);
                    if (mainKey != null)
                    {
                        vl = mainKey.GetValue(string.Empty).ToString();
                    }
                }
                catch
                { }
            }

            //closing the handle:
            if (mainKey != null)
                mainKey.Close();

            return vl;
        }
 public static string returnMinorVersion(OfficeComponent comp)
 {
     string p = GetComponentPath(comp);
     string v = GetMinorVersion(p).ToString();
     return v;
 }
Example #8
0
        /// <summary>
        /// Registry'den Component'in Path'ini Al.
        /// Eğer Component'i Bulamaz ise : Return = string.Empty
        /// </summary>
        static string GetComponentPath(OfficeComponent _component)
        {
            string toReturn = string.Empty;
            string _key     = string.Empty;

            switch (_component)
            {
            case OfficeComponent.Word:
                _key = "winword.exe";
                break;

            case OfficeComponent.Excel:
                _key = "excel.exe";
                break;

            case OfficeComponent.Access:
                _key = "msaccess.exe";
                break;

            case OfficeComponent.PowerPoint:
                _key = "powerpnt.exe";
                break;

            case OfficeComponent.Outlook:
                _key = "outlook.exe";
                break;
            }

            //CURRENT_USER içerisine bak:
            RegistryKey _mainKey = Registry.CurrentUser;

            try
            {
                _mainKey = _mainKey.OpenSubKey(RegKey + "\\" + _key, false);
                if (_mainKey != null)
                {
                    toReturn = _mainKey.GetValue(string.Empty).ToString();
                }
            }
            catch
            {
            }

            //Bulamaz ise, LOCAL_MACHINE içerisine bak:
            _mainKey = Registry.LocalMachine;
            if (string.IsNullOrEmpty(toReturn))
            {
                try
                {
                    _mainKey = _mainKey.OpenSubKey(RegKey + "\\" + _key, false);
                    if (_mainKey != null)
                    {
                        toReturn = _mainKey.GetValue(string.Empty).ToString();
                    }
                }
                catch
                {
                }
            }

            //Elde tuttuğumuz registerykey 'i kapat:
            if (_mainKey != null)
            {
                _mainKey.Close();
            }

            return(toReturn);
        }
Example #9
0
 /// <summary>
 /// Istenen Office Componentinin Version Numarasını Verir.
 /// Eger Component Bulunamamış ise : Return = 0
 /// </summary>
 /// <param name="_component"></param>
 /// <returns>Version Number</returns>
 public static int GetVersionNumber(OfficeComponent _component)
 {
     return(GetMajorVersion(GetComponentPath(_component)));
 }
Example #10
0
        private string GetComponentPath(OfficeComponent _component)
        {
            const string RegKey = @"Software\Microsoft\Windows\CurrentVersion\App Paths";
            string toReturn = string.Empty;
            string _key = string.Empty;

            switch (_component)
            {
                case OfficeComponent.Word:
                    _key = "winword.exe";
                    break;
                case OfficeComponent.Excel:
                    _key = "excel.exe";
                    break;
                case OfficeComponent.PowerPoint:
                    _key = "powerpnt.exe";
                    break;
                case OfficeComponent.Outlook:
                    _key = "outlook.exe";
                    break;
            }

            //looks inside CURRENT_USER:
            RegistryKey _mainKey = Registry.CurrentUser;
            try
            {
                _mainKey = _mainKey.OpenSubKey(RegKey + "\\" + _key, false);
                if (_mainKey != null)
                {
                    toReturn = _mainKey.GetValue(string.Empty).ToString();
                }
            }
            catch
            { }

            //if not found, looks inside LOCAL_MACHINE:
            _mainKey = Registry.LocalMachine;
            if (string.IsNullOrEmpty(toReturn))
            {
                try
                {
                    _mainKey = _mainKey.OpenSubKey(RegKey + "\\" + _key, false);
                    if (_mainKey != null)
                    {
                        toReturn = _mainKey.GetValue(string.Empty).ToString();
                    }
                }
                catch
                { }
            }

            //closing the handle:
            if (_mainKey != null)
                _mainKey.Close();

            return toReturn;
        }
Example #11
0
        public string GetInstalledVersionOfficeAsText(OfficeComponent officeComponent)
        {
            string version = string.Empty;

            switch (GetInstalledOfficeVersion(officeComponent))
            {
                case 15: version = "MS Office 2013 - "; break;
                case 14: version = "MS Office 2010 - "; break;
                case 12: version = "MS Office 2007 - "; break;
                case 11: version = "MS Office 2003 - "; break;
                case 10: version = "MS Office 2002 - "; break;
                case 9: version = "MS Office 2000 - "; break;
                case 8: version = "MS Office 97 - "; break;
                case 7: version = "MS Office 95 - "; break;
                default: version = "ikke installert office, eller en nyere versjon enn Office 2013."; break;
            }
            return version + officeComponent.ToString();
        }
Example #12
0
 public int GetInstalledOfficeVersion(OfficeComponent officeComponent)
 {
     string path = GetComponentPath(officeComponent);
     return GetMajorVersion(path);
 }
Example #13
0
        private string GetComponentPath(OfficeComponent _component)
        {
            const string RegKey   = @"Software\Microsoft\Windows\CurrentVersion\App Paths";
            string       toReturn = string.Empty;
            string       _key     = string.Empty;

            switch (_component)
            {
            case OfficeComponent.Word:
                _key = "winword.exe";
                break;

            case OfficeComponent.Excel:
                _key = "excel.exe";
                break;

            case OfficeComponent.PowerPoint:
                _key = "powerpnt.exe";
                break;

            case OfficeComponent.Outlook:
                _key = "outlook.exe";
                break;
            }

            //looks inside CURRENT_USER:
            RegistryKey _mainKey = Registry.CurrentUser;

            try
            {
                _mainKey = _mainKey.OpenSubKey(RegKey + "\\" + _key, false);
                if (_mainKey != null)
                {
                    toReturn = _mainKey.GetValue(string.Empty).ToString();
                }
            }
            catch
            { }

            //if not found, looks inside LOCAL_MACHINE:
            _mainKey = Registry.LocalMachine;
            if (string.IsNullOrEmpty(toReturn))
            {
                try
                {
                    _mainKey = _mainKey.OpenSubKey(RegKey + "\\" + _key, false);
                    if (_mainKey != null)
                    {
                        toReturn = _mainKey.GetValue(string.Empty).ToString();
                    }
                }
                catch
                { }
            }

            //closing the handle:
            if (_mainKey != null)
            {
                _mainKey.Close();
            }

            return(toReturn);
        }
Example #14
0
        public int GetInstalledOfficeVersion(OfficeComponent officeComponent)
        {
            string path = GetComponentPath(officeComponent);

            return(GetMajorVersion(path));
        }
Example #15
0
        private static string GetComponentPath(OfficeComponent officeComponent)
        {
            const string RegKey = @"Software\Microsoft\Windows\CurrentVersion\App Paths";
            string       vl     = string.Empty;
            string       key    = string.Empty;

            switch (officeComponent)
            {
            case OfficeComponent.Word:
                key = "winword.exe";
                break;

            case OfficeComponent.Excel:
                key = "excel.exe";
                break;

            case OfficeComponent.PowerPoint:
                key = "powerpnt.exe";
                break;

            case OfficeComponent.Outlook:
                key = "outlook.exe";
                break;

            case OfficeComponent.Access:
                key = "msaccess.exe";
                break;

            default:
                break;
            }

            //looks in CURRENT_USER:
            RegistryKey mainKey = Registry.CurrentUser;

            try
            {
                mainKey = mainKey.OpenSubKey(RegKey + "\\" + key, false);
                if (mainKey != null)
                {
                    vl = mainKey.GetValue(string.Empty).ToString();
                }
            }
            catch
            { }

            //if not found, looks inside LOCAL_MACHINE:
            mainKey = Registry.LocalMachine;
            if (string.IsNullOrEmpty(vl))
            {
                try
                {
                    mainKey = mainKey.OpenSubKey(RegKey + "\\" + key, false);
                    if (mainKey != null)
                    {
                        vl = mainKey.GetValue(string.Empty).ToString();
                    }
                }
                catch
                { }
            }

            //closing the handle:
            if (mainKey != null)
            {
                mainKey.Close();
            }

            return(vl);
        }
Example #16
0
        private static string GetComponentPath(OfficeComponent component)
        {
            string toReturn = string.Empty;
            string key = string.Empty;

            switch (component)
            {
                case OfficeComponent.Word:
                    key = "winword.exe";
                    break;
                case OfficeComponent.Excel:
                    key = "excel.exe";
                    break;
                case OfficeComponent.PowerPoint:
                    key = "powerpnt.exe";
                    break;
                case OfficeComponent.Outlook:
                    key = "outlook.exe";
                    break;
            }

            //looks inside CURRENT_USER:
            RegistryKey mainKey = Registry.CurrentUser;
            try
            {
                mainKey = mainKey.OpenSubKey(RegKey + "\\" + key, false);
                if (mainKey != null)
                {
                    toReturn = mainKey.GetValue(string.Empty).ToString();
                }
            }
            catch
            {
            }

            //if not found, looks inside LOCAL_MACHINE:
            mainKey = Registry.LocalMachine;
            if (string.IsNullOrEmpty(toReturn))
            {
                try
                {
                    mainKey = mainKey.OpenSubKey(RegKey + "\\" + key, false);
                    if (mainKey != null)
                    {
                        toReturn = mainKey.GetValue(string.Empty).ToString();
                    }
                }
                catch
                {
                }
            }

            //closing the handle:
            if (mainKey != null)
                mainKey.Close();

            return toReturn;
        }