Microsoft.OfficeProPlus.InstallGenerator.Implementation.OfficeLocalInstallManager.CheckForOfficeInstallAsync C# (CSharp) Method

CheckForOfficeInstallAsync() public method

public CheckForOfficeInstallAsync ( ) : Task
return Task
        public async Task<OfficeInstallation> CheckForOfficeInstallAsync()
        {
            var localInstall = new OfficeInstallation()
            {
                Installed = false
            };

            var officeRegKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Office\ClickToRun\Configuration");
            if (officeRegKey == null)
            {
                officeRegKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Office\16.0\ClickToRun\Configuration");
                if (officeRegKey == null)
                {
                    officeRegKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Office\15.0\ClickToRun\Configuration");
                }
            }
            if (officeRegKey != null)
            {
                localInstall.Version = GetRegistryValue(officeRegKey, "VersionToReport");
                if (string.IsNullOrEmpty(localInstall.Version)) return localInstall;

                localInstall.Installed = true;
                
                var currentBaseCDNUrl = GetRegistryValue(officeRegKey, "CDNBaseUrl");
 
                var installFile = await GetOfficeInstallFileXml();
                if (installFile == null) return localInstall;

                var currentBranch = installFile.BaseURL.FirstOrDefault(b => b.URL.Equals(currentBaseCDNUrl) &&
                                                                            !b.Branch.ToLower().Contains("business"));
                if (currentBranch != null)
                {
                    localInstall.Channel = currentBranch.Branch;

                    var latestVersion = await GetOfficeLatestVersion(currentBranch.Branch, OfficeEdition.Office32Bit);
                    localInstall.LatestVersion = latestVersion;
                }
            }

            return localInstall;
        }

Usage Example

        public async Task <OfficeInstallation> CheckForOfficeInstallAsync()
        {
            var result = new OfficeInstallation();

            if (isLocal)
            {
                result = await LocalInstall.CheckForOfficeInstallAsync();
            }
            else
            {
                switch (_connectionType)
                {
                case ConnectionType.WMI:
                    result = await WmiInstall.CheckForOfficeInstallAsync();

                    break;

                case ConnectionType.PowerShell:
                    result = await PowershellInstall.CheckForOfficeInstallAsync();

                    break;

                default:
                    throw new Exception("Connection Unknown");
                }
            }

            return(result);
        }
All Usage Examples Of Microsoft.OfficeProPlus.InstallGenerator.Implementation.OfficeLocalInstallManager::CheckForOfficeInstallAsync