# Enable TLSv1.2 for compatibility with older clients [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor [System.Net.SecurityProtocolType]::Tls12 # Do not display progress for WebRequest $ProgressPreference = 'SilentlyContinue' function Get-OTP { param([string]$DownloadURL, [string]$SavePath) $FileName = "$env:TEMP\Office Tool Plus.zip" $DownloadSuccess = $false do { try { Write-Host " Downloading Office Tool Plus, please wait." Invoke-WebRequest -Uri $DownloadURL -UseBasicParsing -OutFile $FileName -ErrorAction Stop Write-Host " Extracting files, please wait." Expand-Archive -LiteralPath $FileName -DestinationPath $SavePath -Force $DownloadSuccess = $true } catch { Write-Host " An error occurred while downloading the file." $userChoice = Read-Host " Do you want to retry? (Y/N)" if ($userChoice -ne "Y") { Write-Host " Please download Office Tool Plus from http://officetool.plus/ or try again." Read-Host Exit } } finally { Write-Host " Cleaning files..." if (Test-Path $FileName) { $item = Get-Item -LiteralPath $FileName $item.Delete() } } } while (-not $DownloadSuccess) } function Get-RuntimeVersion { try { $dotnetInfo = dotnet --list-runtimes | Select-String -Pattern "Microsoft.WindowsDesktop.App 8" if ($null -ne $dotnetInfo) { return $true } } catch { return $false } return $false } Function Get-FolderName { [CmdletBinding()] [OutputType([string])] Param ( # InitialDirectory help description [Parameter( Mandatory = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Initial Directory for browsing", Position = 0)] [String]$SelectedPath, # Description help description [Parameter( Mandatory = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Message Box Title")] [String]$Description="Select a folder", # ShowNewFolderButton help description [Parameter( Mandatory = $false, HelpMessage = "Show New Folder Button when used")] [Switch]$ShowNewFolderButton ) # Load Assembly Add-Type -AssemblyName System.Windows.Forms # Open Class $FolderBrowser= New-Object System.Windows.Forms.FolderBrowserDialog # Define Title $FolderBrowser.Description = $Description # Define Initial Directory if (-Not [String]::IsNullOrWhiteSpace($SelectedPath)) { $FolderBrowser.SelectedPath=$SelectedPath } if($folderBrowser.ShowDialog() -eq "OK") { $Folder += $FolderBrowser.SelectedPath } return $Folder } $Host.UI.RawUI.WindowTitle = "Office Tool Plus | Downloader" Clear-Host # Collect system information $osVer = [System.Environment]::OSVersion.VersionString $platform = [System.Environment]::OSVersion.Platform $arch = (Get-CimInstance Win32_OperatingSystem).OSArchitecture $arch = if ($arch -Match "ARM64") {"ARM64"} elseif ($arch -Match "64") {"x64"} else {"x86"} $desktopPath = [Environment]::GetFolderPath("Desktop") Write-Host "============================== Office Tool Plus ==============================" Write-Host Write-Host " OS info: $osVer $arch" Write-Host Write-Host " Select the save location for Office Tool Plus:" Write-Host Write-Host " 1: Desktop" Write-Host " 2: Select a folder" Write-Host $userChoice = Read-Host " Please enter 1 or 2" switch ($userChoice) { "1" { $userSpecifiedPath = $desktopPath } "2" { Write-Host " If you don't see the window to select the folder, it may be behind the window." $userSpecifiedPath = Get-FolderName -SelectedPath $desktopPath if ($null -eq $userSpecifiedPath) { Write-Host " Invalid choice, defaulting to Desktop." $userSpecifiedPath = $desktopPath } } default { Write-Host " Invalid choice, defaulting to Desktop." $userSpecifiedPath = $desktopPath } } if ($platform -match "Win32NT" -AND $osVer -match "10.0") { Write-Host $DownloadURL = $null if (Get-RuntimeVersion -eq $true) { $DownloadURL = "https://officetool.plus/redirect/download.php?type=normal&arch=$arch" Write-Host " We recommend you to download the $arch version of Office Tool Plus." } else { $DownloadURL = "https://officetool.plus/redirect/download.php?type=runtime&arch=$arch" Write-Host " We recommend you to download the $arch version of Office Tool Plus with runtime." } Write-Host " Press Enter to continue." -NoNewline Read-Host Get-OTP -DownloadURL $DownloadURL -SavePath $userSpecifiedPath Clear-Host Write-Host "============================== Office Tool Plus ==============================" Write-Host Write-Host " Office Tool Plus was extracted to $userSpecifiedPath\Office Tool" Write-Host Write-Host " Press Enter to start the program, or close the window to exit." Read-Host Start-Process "$userSpecifiedPath\Office Tool\Office Tool Plus.exe" Exit } else { Write-Host " Your operating system is not supported. Press Enter to exit." Read-Host Exit }