135 lines
6.5 KiB
PowerShell
135 lines
6.5 KiB
PowerShell
# ==============================================================================
|
|
# Script Name: 8x8_Work_Updater.ps1
|
|
# Description: Downloads 8x8 with a progress bar, triggers a blocking 1-hour
|
|
# popup alert, silently installs, and launches 8x8 under the standard
|
|
# user session via Explorer.
|
|
# ==============================================================================
|
|
|
|
# Ensure script is running elevated
|
|
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
|
|
Write-Error "This script must be executed with Administrator privileges."
|
|
exit 1
|
|
}
|
|
|
|
# Load required .NET assemblies
|
|
Add-Type -AssemblyName System.Net.Http
|
|
|
|
$workDir = "C:\ProgramData\JCT600_8x8Update"
|
|
$installerPath = Join-Path $workDir "8x8_Work_Installer.msi"
|
|
$vbsAlertPath = Join-Path $workDir "ShowUserAlert.vbs"
|
|
|
|
if (-not (Test-Path $workDir)) {
|
|
New-Item -Path $workDir -ItemType Directory -Force | Out-Null
|
|
}
|
|
|
|
try {
|
|
# --------------------------------------------------------------------------
|
|
# Step 1: Download 8x8 Setup Installer with Console Progress Bar
|
|
# --------------------------------------------------------------------------
|
|
$installerUrl = "https://work-desktop-assets.8x8.com/prod-publish/ga/work-64-msi-v8.35.2-6.msi"
|
|
Write-Host "[1/4] Downloading 8x8 Work installer..." -ForegroundColor Cyan
|
|
|
|
try {
|
|
$httpClient = New-Object System.Net.Http.HttpClient
|
|
$response = $httpClient.GetAsync($installerUrl, [System.Net.Http.HttpCompletionOption]::ResponseHeadersRead).Result
|
|
|
|
if (-not $response.IsSuccessStatusCode) { throw "HTTP Error $($response.StatusCode)" }
|
|
|
|
$totalBytes = $response.Content.Headers.ContentLength
|
|
$inputStream = $response.Content.ReadAsStreamAsync().Result
|
|
$outputStream = [System.IO.File]::Create($installerPath)
|
|
$buffer = New-Object byte[] 8192
|
|
$totalBytesRead = 0; $bytesRead = 0
|
|
|
|
while (($bytesRead = $inputStream.Read($buffer, 0, $buffer.Length)) -gt 0) {
|
|
$outputStream.Write($buffer, 0, $bytesRead)
|
|
$totalBytesRead += $bytesRead
|
|
|
|
if ($totalBytes -gt 0) {
|
|
$percent = [math]::Round(($totalBytesRead / $totalBytes) * 100)
|
|
$downloadedMB = [math]::Round($totalBytesRead / 1MB, 2)
|
|
$totalMB = [math]::Round($totalBytes / 1MB, 2)
|
|
$barLength = 30
|
|
$filledLength = [math]::Round(($percent / 100) * $barLength)
|
|
$bar = ("█" * $filledLength) + ("░" * ($barLength - $filledLength))
|
|
|
|
Write-Host "`rDownloading: [$bar] $percent% ($downloadedMB MB / $totalMB MB)" -NoNewline -ForegroundColor Yellow
|
|
}
|
|
}
|
|
$outputStream.Close(); $inputStream.Close(); $httpClient.Dispose()
|
|
Write-Host "`nDownload complete: $installerPath" -ForegroundColor Green
|
|
} catch {
|
|
Write-Error "`nFailed to download installer. Error: $_"
|
|
exit 1
|
|
}
|
|
|
|
# --------------------------------------------------------------------------
|
|
# Step 2: Trigger Blocking Interactive Popup (Waits for Click or 1 Hour)
|
|
# --------------------------------------------------------------------------
|
|
Write-Host "[2/4] Triggering interactive alert on active user's desktop..." -ForegroundColor Cyan
|
|
|
|
# Generate a blocking VBScript WshShell.Popup (Type 48 = Exclamation, 4096 = System Modal / Always on top)
|
|
$vbsContent = @"
|
|
Set wshShell = CreateObject("WScript.Shell")
|
|
intButton = wshShell.Popup("An automatic update for 8x8 Work has been scheduled by JCT600 IT Support." & vbCrLf & vbCrLf & "Please save active work and finish ongoing calls." & vbCrLf & vbCrLf & "Click OK or close this window to update immediately, or wait for the 1-hour timer.", 3600, "JCT600 IT Support — 8x8 Work Update", 48 + 4096)
|
|
"@
|
|
|
|
[System.IO.File]::WriteAllText($vbsAlertPath, $vbsContent, [System.Text.Encoding]::ASCII)
|
|
|
|
# Launch popup and WAIT for user click or 3600-second timeout
|
|
Write-Host "Waiting for user acknowledgment or 1-hour timeout..." -ForegroundColor Yellow
|
|
$popupProcess = Start-Process "wscript.exe" -ArgumentList "`"$vbsAlertPath`"" -Wait -PassThru
|
|
|
|
# --------------------------------------------------------------------------
|
|
# Step 3: Close Running 8x8 Processes & Install Silently
|
|
# --------------------------------------------------------------------------
|
|
Write-Host "[3/4] Stopping 8x8 processes and installing silently..." -ForegroundColor Cyan
|
|
|
|
$targetProcesses = Get-Process | Where-Object {
|
|
$_.ProcessName -like "*8x8*" -or $_.MainWindowTitle -like "*8x8*"
|
|
}
|
|
|
|
if ($targetProcesses) {
|
|
foreach ($proc in $targetProcesses) {
|
|
Stop-Process -Id $proc.Id -Force -ErrorAction SilentlyContinue
|
|
}
|
|
Start-Sleep -Seconds 3
|
|
}
|
|
|
|
$msiArgs = "/i `"$installerPath`" /quiet /norestart"
|
|
$installJob = Start-Process msiexec.exe -ArgumentList $msiArgs -Wait -PassThru
|
|
|
|
if ($installJob.ExitCode -ne 0 -and $installJob.ExitCode -ne 3010) {
|
|
Write-Error "Installation failed with exit code $($installJob.ExitCode)."
|
|
exit $installJob.ExitCode
|
|
}
|
|
|
|
Write-Host "Installation completed successfully." -ForegroundColor Green
|
|
|
|
# --------------------------------------------------------------------------
|
|
# Step 4: Launch 8x8 Work via Explorer (User Context)
|
|
# --------------------------------------------------------------------------
|
|
Write-Host "[4/4] Launching 8x8 Work in user session..." -ForegroundColor Cyan
|
|
|
|
$possiblePaths = @(
|
|
"${env:ProgramFiles}\8x8 Inc\8x8 Work\8x8 Work.exe",
|
|
"${env:ProgramFiles(x86)}\8x8 Inc\8x8 Work\8x8 Work.exe",
|
|
"${env:ProgramFiles}\8x8 Work\8x8 Work.exe",
|
|
"$env:LocalAppData\Programs\8x8 Work\8x8 Work.exe"
|
|
)
|
|
|
|
$exePath = $possiblePaths | Where-Object { Test-Path $_ } | Select-Object -First 1
|
|
|
|
if ($exePath) {
|
|
# Using explorer.exe to launch the executable forces Windows to run 8x8 in
|
|
# the interactive standard user's desktop context, preventing GPU crashes.
|
|
Start-Process "explorer.exe" -ArgumentList "`"$exePath`""
|
|
Write-Host "8x8 Work launched successfully." -ForegroundColor Green
|
|
} else {
|
|
Write-Warning "Could not locate 8x8 Work executable."
|
|
}
|
|
|
|
} finally {
|
|
Write-Host "Cleaning up temporary files..." -ForegroundColor Gray
|
|
if (Test-Path $workDir) { Remove-Item $workDir -Recurse -Force -ErrorAction SilentlyContinue }
|
|
} |