# ============================================================================== # Script Name: 8x8_Work_Updater.ps1 # Description: Downloads 8x8 with a progress bar, detects the active interactive # desktop user, presents the unclosable HTA countdown prompt, # installs silently, relaunches 8x8 Work, and logs everything to # C:\IntuneLogs\8x8Updater_log.txt. # ============================================================================== # 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 } Add-Type -AssemblyName System.Net.Http # Configure logging directory and log file $logDir = "C:\IntuneLogs" $logFile = Join-Path $logDir "8x8Updater_log.txt" if (-not (Test-Path $logDir)) { New-Item -Path $logDir -ItemType Directory -Force | Out-Null } function Write-Log { param ( [string]$Message, [ConsoleColor]$Color = [ConsoleColor]::Gray ) $timestamp = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss") $logLine = "[$timestamp] $Message" # Output to Console Write-Host $Message -ForegroundColor $Color # Append to Log File Add-Content -Path $logFile -Value $logLine -Force } $workDir = "C:\ProgramData\JCT600_8x8Update" $flagFile = Join-Path $workDir "8x8_Update_Proceed.flag" $htaPromptPath = Join-Path $workDir "Show-8x8Prompt.hta" $installerPath = Join-Path $workDir "8x8_Work_Installer.msi" if (-not (Test-Path $workDir)) { New-Item -Path $workDir -ItemType Directory -Force | Out-Null } $acl = Get-Acl $workDir $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("BUILTIN\Users", "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow") $acl.AddAccessRule($rule) Set-Acl $workDir $acl if (Test-Path $flagFile) { Remove-Item $flagFile -Force } Write-Log "========== Starting 8x8 Work Update Script ==========" -Color Cyan 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.36.2-3.msi" Write-Log "[1/4] Downloading 8x8 Work installer from $installerUrl..." -Color 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 "" # Newline after progress bar Write-Log "Download complete: $installerPath ($([math]::Round($totalBytesRead / 1MB, 2)) MB)" -Color Green } catch { Write-Log "Failed to download installer. Error: $_" -Color Red exit 1 } # -------------------------------------------------------------------------- # Step 2: Generate Sleep-Safe Wall-Clock HTA Countdown Dialog # -------------------------------------------------------------------------- Write-Log "[2/4] Generating sleep-safe unclosable dialog..." -Color Cyan $htaContent = @" JCT600 IT Support - 8x8 Work Update
JCT600 - IT SUPPORT
An automatic update for 8x8 Work has been scheduled.
Please save active work or click Update Now to begin.
60:00
"@ [System.IO.File]::WriteAllText($htaPromptPath, $htaContent, [System.Text.Encoding]::ASCII) # -------------------------------------------------------------------------- # Step 3: Detect Active Desktop User & Launch HTA Prompt # -------------------------------------------------------------------------- Write-Log "[3/4] Detecting active console user and launching dialog..." -Color Cyan $explorerProc = Get-Process -Name explorer -ErrorAction SilentlyContinue | Select-Object -First 1 if (-not $explorerProc) { Write-Log "No active interactive desktop detected. Proceeding directly to update." -Color Yellow } else { $ownerInfo = Get-CimInstance -ClassName Win32_Process -Filter "ProcessId = $($explorerProc.Id)" | Invoke-CimMethod -MethodName GetOwner $activeUser = "$($ownerInfo.Domain)\$($ownerInfo.User)" Write-Log "Active Desktop User: $activeUser (Session ID: $($explorerProc.SessionId))" -Color Green $taskName = "JCT600_8x8_UpdatePrompt" $action = New-ScheduledTaskAction -Execute "mshta.exe" -Argument "`"$htaPromptPath`"" $trigger = New-ScheduledTaskTrigger -At (Get-Date).AddSeconds(2) -Once $principal = New-ScheduledTaskPrincipal -UserId $activeUser -LogonType Interactive -RunLevel Limited $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit (New-TimeSpan -Hours 2) Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Principal $principal -Settings $settings -Force | Out-Null Start-ScheduledTask -TaskName $taskName | Out-Null Write-Log "Dialog prompt active. Waiting for user action or 1-hour expiration..." -Color Yellow while (-not (Test-Path $flagFile)) { Start-Sleep -Seconds 2 } Write-Log "User action/timeout received. Proceeding with installation." -Color Green Unregister-ScheduledTask -TaskName $taskName -Confirm:$false -ErrorAction SilentlyContinue } # -------------------------------------------------------------------------- # Step 4: Close 8x8 Processes & Install Silently # -------------------------------------------------------------------------- Write-Log "[4/4] Stopping active 8x8 processes and installing silently..." -Color Cyan $targetProcesses = Get-Process | Where-Object { $_.ProcessName -like "*8x8*" -or $_.MainWindowTitle -like "*8x8*" } if ($targetProcesses) { foreach ($proc in $targetProcesses) { Write-Log "Stopping process: $($proc.ProcessName) (PID: $($proc.Id))" -Color Yellow Stop-Process -Id $proc.Id -Force -ErrorAction SilentlyContinue } Start-Sleep -Seconds 3 } $msiLogPath = Join-Path $logDir "8x8_MSI_Install.log" $msiArgs = "/i `"$installerPath`" /quiet /norestart /lv* `"$msiLogPath`"" Write-Log "Executing: msiexec.exe $msiArgs" -Color Cyan $installJob = Start-Process msiexec.exe -ArgumentList $msiArgs -Wait -PassThru if ($installJob.ExitCode -ne 0 -and $installJob.ExitCode -ne 3010) { Write-Log "MSI Installation failed with exit code $($installJob.ExitCode)." -Color Red exit $installJob.ExitCode } Write-Log "MSI Installation completed successfully with ExitCode $($installJob.ExitCode)." -Color Green # -------------------------------------------------------------------------- # Step 5: Relaunch 8x8 Work in Active User Session # -------------------------------------------------------------------------- Write-Log "Launching updated 8x8 Work..." -Color 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) { if ($explorerProc -and $activeUser) { $launchTask = "JCT600_8x8_Launch" $launchAction = New-ScheduledTaskAction -Execute "explorer.exe" -Argument "`"$exePath`"" $launchTrigger = New-ScheduledTaskTrigger -At (Get-Date).AddSeconds(2) -Once $launchPrincipal = New-ScheduledTaskPrincipal -UserId $activeUser -LogonType Interactive -RunLevel Limited Register-ScheduledTask -TaskName $launchTask -Action $launchAction -Trigger $launchTrigger -Principal $launchPrincipal -Force | Out-Null Start-ScheduledTask -TaskName $launchTask | Out-Null Start-Sleep -Seconds 4 Unregister-ScheduledTask -TaskName $launchTask -Confirm:$false -ErrorAction SilentlyContinue Write-Log "8x8 Work launched successfully for $activeUser." -Color Green } else { Start-Process "explorer.exe" -ArgumentList "`"$exePath`"" Write-Log "8x8 Work started via explorer.exe fallback." -Color Green } } else { Write-Log "Could not locate 8x8 Work executable on disk." -Color Yellow } } catch { Write-Log "Unexpected script error: $_" -Color Red } finally { Write-Log "Cleaning up temporary files..." -Color Gray if (Test-Path $workDir) { Remove-Item $workDir -Recurse -Force -ErrorAction SilentlyContinue } Write-Log "========== 8x8 Work Update Script Finished ==========" -Color Cyan }