diff --git a/8x8_Work_Updater.ps1 b/8x8_Work_Updater.ps1 index 5ae71bf..7dfe4d6 100644 --- a/8x8_Work_Updater.ps1 +++ b/8x8_Work_Updater.ps1 @@ -1,8 +1,8 @@ # ============================================================================== # Script Name: 8x8_Work_Updater.ps1 -# Description: Downloads 8x8, uses ServiceUI (from internal Gitea) to display -# a 1-hour countdown GUI directly on the active user's desktop, -# silently installs 8x8, and relaunches it. +# Description: Downloads 8x8 with a progress bar, pops up an interactive +# unclosable countdown window (1-hour timer with "Update Now"), +# silently installs 8x8, and launches the updated client. # ============================================================================== # Ensure script is running elevated @@ -11,41 +11,26 @@ if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdenti exit 1 } +# Load required .NET assemblies +Add-Type -AssemblyName System.Windows.Forms +Add-Type -AssemblyName System.Drawing Add-Type -AssemblyName System.Net.Http $workDir = "C:\ProgramData\JCT600_8x8Update" -$flagFile = Join-Path $workDir "8x8_Update_Proceed.flag" -$guiScript = Join-Path $workDir "Show-8x8UserGui.ps1" -$serviceUiPath = Join-Path $workDir "ServiceUI.exe" $installerPath = Join-Path $workDir "8x8_Work_Installer.msi" -$serviceUiLog = Join-Path $workDir "ServiceUI.log" if (-not (Test-Path $workDir)) { New-Item -Path $workDir -ItemType Directory -Force | Out-Null } -# Grant standard users permissions to the directory -$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 } - try { # -------------------------------------------------------------------------- - # Step 1: Download 8x8 Installer & ServiceUI from internal Gitea + # Step 1: Download 8x8 Installer with Stream Progress Bar # -------------------------------------------------------------------------- $installerUrl = "https://work-desktop-assets.8x8.com/prod-publish/ga/work-64-msi-v8.35.2-6.msi" - $serviceUiUrl = "https://gitea.ostroveni.com/JCT/8x8-Work-updater/raw/branch/main/ServiceUI.exe" - - Write-Host "[1/5] Downloading 8x8 Work installer and helper tools..." -ForegroundColor Cyan + Write-Host "[1/4] Downloading 8x8 Work installer..." -ForegroundColor Cyan try { - # Download ServiceUI from internal Gitea - Invoke-WebRequest -Uri $serviceUiUrl -OutFile $serviceUiPath -UseBasicParsing - - # Download 8x8 Installer with stream progress bar $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)" } @@ -74,143 +59,100 @@ try { $outputStream.Close(); $inputStream.Close(); $httpClient.Dispose() Write-Host "`nDownload complete: $installerPath" -ForegroundColor Green } catch { - Write-Error "`nFailed to download installer or tools. Error: $_" + Write-Error "`nFailed to download installer. Error: $_" exit 1 } # -------------------------------------------------------------------------- - # Step 2: Write User-Session GUI Script (BOM-Free UTF-8) + # Step 2: Show Interactive JCT600 Dialog Form # -------------------------------------------------------------------------- - Write-Host "[2/5] Generating user-session GUI dialog script..." -ForegroundColor Cyan + Write-Host "[2/4] Displaying interactive countdown dialog..." -ForegroundColor Cyan - $guiContent = @' -Add-Type -AssemblyName System.Windows.Forms -Add-Type -AssemblyName System.Drawing + [System.Windows.Forms.Application]::EnableVisualStyles() -$signature = @" -[DllImport("user32.dll", SetLastError = true)] -public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); -"@ -$Win32SetWindowPos = Add-Type -memberDefinition $signature -Name "Win32SetWindowPos" -namespace Win32Functions -passThru + $form = New-Object System.Windows.Forms.Form + $form.Text = "JCT600 IT Support — 8x8 Work Update" + $form.Size = New-Object System.Drawing.Size(460, 260) + $form.StartPosition = 'CenterScreen' + $form.FormBorderStyle = 'FixedDialog' + $form.MaximizeBox = $false + $form.MinimizeBox = $false + $form.ControlBox = $false + $form.TopMost = $true -$flagPath = "C:\ProgramData\JCT600_8x8Update\8x8_Update_Proceed.flag" + $script:allowClose = $false + $form.Add_FormClosing({ + param($sender, $e) + if (-not $script:allowClose) { $e.Cancel = $true } + }) -$form = New-Object System.Windows.Forms.Form -$form.Text = "JCT600 IT Support — 8x8 Work Update" -$form.Size = New-Object System.Drawing.Size(440, 250) -$form.StartPosition = 'CenterScreen' -$form.FormBorderStyle = 'FixedDialog' -$form.MaximizeBox = $false -$form.MinimizeBox = $false -$form.ControlBox = $false -$form.TopMost = $true + $labelHeader = New-Object System.Windows.Forms.Label + $labelHeader.Text = "JCT600 — IT SUPPORT" + $labelHeader.Location = New-Object System.Drawing.Point(20, 15) + $labelHeader.Size = New-Object System.Drawing.Size(400, 25) + $labelHeader.Font = New-Object System.Drawing.Font("Segoe UI", 12, [System.Drawing.FontStyle]::Bold) + $labelHeader.ForeColor = [System.Drawing.Color]::Navy + $labelHeader.TextAlign = 'TopCenter' + $form.Controls.Add($labelHeader) -$script:allowClose = $false -$form.Add_FormClosing({ - param($sender, $e) - if (-not $script:allowClose) { $e.Cancel = $true } -}) + $labelMsg = New-Object System.Windows.Forms.Label + $labelMsg.Text = "An automatic update for 8x8 Work has been scheduled by IT Support.`nPlease save active work or click 'Update Now' to proceed." + $labelMsg.Location = New-Object System.Drawing.Point(20, 48) + $labelMsg.Size = New-Object System.Drawing.Size(400, 40) + $labelMsg.Font = New-Object System.Drawing.Font("Segoe UI", 9) + $labelMsg.TextAlign = 'TopCenter' + $form.Controls.Add($labelMsg) -$labelHeader = New-Object System.Windows.Forms.Label -$labelHeader.Text = "JCT600 — IT SUPPORT" -$labelHeader.Location = New-Object System.Drawing.Point(20, 15) -$labelHeader.Size = New-Object System.Drawing.Size(380, 25) -$labelHeader.Font = New-Object System.Drawing.Font("Segoe UI", 11, [System.Drawing.FontStyle]::Bold) -$labelHeader.ForeColor = [System.Drawing.Color]::Navy -$labelHeader.TextAlign = 'TopCenter' -$form.Controls.Add($labelHeader) + $labelTimer = New-Object System.Windows.Forms.Label + $labelTimer.Location = New-Object System.Drawing.Point(20, 95) + $labelTimer.Size = New-Object System.Drawing.Size(400, 40) + $labelTimer.Font = New-Object System.Drawing.Font("Segoe UI", 20, [System.Drawing.FontStyle]::Bold) + $labelTimer.ForeColor = [System.Drawing.Color]::DarkRed + $labelTimer.TextAlign = 'MiddleCenter' + $form.Controls.Add($labelTimer) -$labelMsg = New-Object System.Windows.Forms.Label -$labelMsg.Text = "An automatic update for 8x8 Work has been scheduled by IT Support.`nPlease save active work or click 'Update Now' to begin." -$labelMsg.Location = New-Object System.Drawing.Point(20, 45) -$labelMsg.Size = New-Object System.Drawing.Size(380, 45) -$labelMsg.Font = New-Object System.Drawing.Font("Segoe UI", 9) -$labelMsg.TextAlign = 'TopCenter' -$form.Controls.Add($labelMsg) + $btnUpdateNow = New-Object System.Windows.Forms.Button + $btnUpdateNow.Text = "Update Now" + $btnUpdateNow.Font = New-Object System.Drawing.Font("Segoe UI", 10, [System.Drawing.FontStyle]::Bold) + $btnUpdateNow.Size = New-Object System.Drawing.Size(150, 40) + $btnUpdateNow.Location = New-Object System.Drawing.Point(145, 155) + $btnUpdateNow.UseVisualStyleBackColor = $true -$labelTimer = New-Object System.Windows.Forms.Label -$labelTimer.Location = New-Object System.Drawing.Point(20, 95) -$labelTimer.Size = New-Object System.Drawing.Size(380, 40) -$labelTimer.Font = New-Object System.Drawing.Font("Segoe UI", 20, [System.Drawing.FontStyle]::Bold) -$labelTimer.ForeColor = [System.Drawing.Color]::DarkRed -$labelTimer.TextAlign = 'MiddleCenter' -$form.Controls.Add($labelTimer) + $timer = New-Object System.Windows.Forms.Timer + $timer.Interval = 1000 + $script:remaining = 3600 # 1 Hour -$btnUpdateNow = New-Object System.Windows.Forms.Button -$btnUpdateNow.Text = "Update Now" -$btnUpdateNow.Font = New-Object System.Drawing.Font("Segoe UI", 9, [System.Drawing.FontStyle]::Bold) -$btnUpdateNow.Size = New-Object System.Drawing.Size(140, 35) -$btnUpdateNow.Location = New-Object System.Drawing.Point(140, 150) -$btnUpdateNow.UseVisualStyleBackColor = $true - -$btnUpdateNow.Add_Click({ - $timer.Stop() - $script:allowClose = $true - New-Item -Path $flagPath -ItemType File -Force | Out-Null - $form.Close() -}) -$form.Controls.Add($btnUpdateNow) - -$form.Add_Shown({ - [Win32Functions.Win32SetWindowPos]::SetWindowPos($form.Handle, [IntPtr] -1, 0, 0, 0, 0, 0x0003) | Out-Null - $form.Activate() -}) - -$timer = New-Object System.Windows.Forms.Timer -$timer.Interval = 1000 -$script:remaining = 3600 # 1 Hour - -$timer.Add_Tick({ - if ($script:remaining -gt 0) { - $timeSpan = [TimeSpan]::FromSeconds($script:remaining) - $labelTimer.Text = $timeSpan.ToString("hh\:mm\:ss") - $script:remaining-- - [Win32Functions.Win32SetWindowPos]::SetWindowPos($form.Handle, [IntPtr] -1, 0, 0, 0, 0, 0x0003) | Out-Null - } else { + $btnUpdateNow.Add_Click({ $timer.Stop() $script:allowClose = $true - New-Item -Path $flagPath -ItemType File -Force | Out-Null $form.Close() - } -}) + }) + $form.Controls.Add($btnUpdateNow) -$initialSpan = [TimeSpan]::FromSeconds($script:remaining) -$labelTimer.Text = $initialSpan.ToString("hh\:mm\:ss") - -$timer.Start() -$form.ShowDialog() | Out-Null -$timer.Dispose() -$form.Dispose() -'@ - - $utf8NoBom = New-Object System.Text.UTF8Encoding($false) - [System.IO.File]::WriteAllText($guiScript, $guiContent, $utf8NoBom) - - # -------------------------------------------------------------------------- - # Step 3: Launch GUI via ServiceUI Directly into Active User's Session - # -------------------------------------------------------------------------- - Write-Host "[3/5] Launching interactive dialog on active user desktop via ServiceUI..." -ForegroundColor Cyan - - $explorerProc = Get-Process -Name explorer -ErrorAction SilentlyContinue | Select-Object -First 1 - - if (-not $explorerProc) { - Write-Warning "No active desktop session detected. Proceeding directly to update." - } else { - $psExe = "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe" - - # Execute ServiceUI directly with distinct parameters - $process = Start-Process -FilePath $serviceUiPath -ArgumentList "-process:explorer.exe", $psExe, "-ExecutionPolicy", "Bypass", "-NoProfile", "-WindowStyle", "Hidden", "-File", "`"$guiScript`"" -PassThru - - Write-Host "Dialog launched. Waiting for user response or 1-hour expiration..." -ForegroundColor Yellow - while (-not (Test-Path $flagFile)) { - Start-Sleep -Seconds 2 + $timer.Add_Tick({ + if ($script:remaining -gt 0) { + $timeSpan = [TimeSpan]::FromSeconds($script:remaining) + $labelTimer.Text = $timeSpan.ToString("hh\:mm\:ss") + $script:remaining-- + } else { + $timer.Stop() + $script:allowClose = $true + $form.Close() } - } + }) + + $initialSpan = [TimeSpan]::FromSeconds($script:remaining) + $labelTimer.Text = $initialSpan.ToString("hh\:mm\:ss") + + $timer.Start() + $form.ShowDialog() | Out-Null + $timer.Dispose() + $form.Dispose() # -------------------------------------------------------------------------- - # Step 4: Close Running 8x8 Processes & Install Silently + # Step 3: Close Running 8x8 Processes & Install Silently # -------------------------------------------------------------------------- - Write-Host "[4/5] Stopping 8x8 processes and installing silently..." -ForegroundColor Cyan + Write-Host "[3/4] Stopping 8x8 processes and installing silently..." -ForegroundColor Cyan $targetProcesses = Get-Process | Where-Object { $_.ProcessName -like "*8x8*" -or $_.MainWindowTitle -like "*8x8*" @@ -234,9 +176,9 @@ $form.Dispose() Write-Host "Installation completed successfully." -ForegroundColor Green # -------------------------------------------------------------------------- - # Step 5: Launch 8x8 Work in User Session + # Step 4: Launch 8x8 Work # -------------------------------------------------------------------------- - Write-Host "[5/5] Launching 8x8 Work in user session..." -ForegroundColor Cyan + Write-Host "[4/4] Launching 8x8 Work..." -ForegroundColor Cyan $possiblePaths = @( "${env:ProgramFiles}\8x8 Inc\8x8 Work\8x8 Work.exe", @@ -248,12 +190,9 @@ $form.Dispose() $exePath = $possiblePaths | Where-Object { Test-Path $_ } | Select-Object -First 1 if ($exePath) { - if ($explorerProc) { - Start-Process -FilePath $serviceUiPath -ArgumentList "-process:explorer.exe", "`"$exePath`"" - Write-Host "8x8 Work launched successfully in user context." -ForegroundColor Green - } else { - Start-Process -FilePath $exePath - } + # Launching via explorer.exe ensures standard user execution token + Start-Process "explorer.exe" -ArgumentList "`"$exePath`"" + Write-Host "8x8 Work launched successfully." -ForegroundColor Green } else { Write-Warning "Could not locate 8x8 Work executable." }