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);
        }
        public async Task <OfficeInstallation> CheckForOfficeInstallAsync()
        {
            var officeInstance = new OfficeInstallation()
            {
                Installed = false
            };
            string readtext = "";

            try
            {
                string PSPath = System.IO.Path.GetTempPath() + remoteComputerName + "PowershellAttemptVersion.txt";
                System.IO.File.Delete(PSPath);
                using (var powerShellInstance = System.Management.Automation.PowerShell.Create())
                {
                    powerShellInstance.AddScript(System.IO.Directory.GetCurrentDirectory() + "\\Resources\\FindVersion.ps1 -machineToRun " + remoteComputerName);
                    var async = powerShellInstance.Invoke();
                }
                readtext = System.IO.File.ReadAllText(PSPath);
                readtext = readtext.Trim();

                officeInstance.Version = readtext.Split('\\')[0];

                if (!string.IsNullOrEmpty(officeInstance.Version))
                {
                    officeInstance.Installed = true;
                    var currentBaseCDNUrl = readtext.Split('\\')[1];


                    var installFile = await GetOfficeInstallFileXml();

                    if (installFile == null)
                    {
                        return(officeInstance);
                    }

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

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

                        officeInstance.LatestVersion = latestVersion;
                    }
                }
            }
            catch (Exception ex)
            {
                using (System.IO.StreamWriter file =
                           new System.IO.StreamWriter(System.IO.Path.GetTempPath() + "failure.txt", true))
                {
                    file.WriteLine(ex.Message);
                }
                throw new Exception(ex.Message);
            }
            return(officeInstance);
        }
예제 #3
0
        public async Task ChangeOfficeChannelWmi(RemoteMachine client, OfficeInstallation localInstall)
        {
            var    newChannel = client.Channel.ToString();
            string version    = null;

            if (client.Version != null)
            {
                version = client.Version.ToString();
            }

            await Task.Run(async() =>
            {
                var installOffice = new InstallOfficeWmi
                {
                    remoteUser          = client.UserName,
                    remoteComputerName  = client.Machine,
                    remoteDomain        = client.WorkGroup,
                    remotePass          = client.Password,
                    newChannel          = client.Channel.ToString(),
                    newVersion          = version,
                    connectionNamespace = "\\root\\cimv2"
                };

                try
                {
                    var ppDownloader = new ProPlusDownloader();
                    var baseUrl      = await ppDownloader.GetChannelBaseUrlAsync(newChannel, OfficeEdition.Office32Bit);
                    if (string.IsNullOrEmpty(baseUrl))
                    {
                        throw (new Exception(string.Format("Cannot find BaseUrl for Channel: {0}", newChannel)));
                    }

                    var channelToChangeTo = newChannel;

                    if (string.IsNullOrEmpty(channelToChangeTo))
                    {
                        throw (new Exception("Version required"));
                    }

                    await installOffice.ChangeOfficeChannel(channelToChangeTo, baseUrl);
                    var installGenerator = new OfficeInstallManager();
                }
                catch (Exception ex)
                {
                    LogWmiErrorMessage(ex, new RemoteComputer()
                    {
                        Name     = client.Machine,
                        Domain   = client.WorkGroup,
                        UserName = client.UserName,
                        Password = client.Password
                    });
                    throw (new Exception("Update Failed"));
                }
            });
        }
        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);
        }