Update 8x8_Work_Updater.ps1
This commit is contained in:
+56
-22
@@ -1,8 +1,9 @@
|
|||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
# Script Name: 8x8_Work_Updater.ps1
|
# Script Name: 8x8_Work_Updater.ps1
|
||||||
# Description: Downloads 8x8 with a progress bar, detects the active interactive
|
# Description: Downloads 8x8 with a progress bar, detects the active interactive
|
||||||
# desktop user dynamically, presents the unclosable HTA countdown
|
# desktop user, presents the unclosable HTA countdown prompt,
|
||||||
# prompt, installs silently, and relaunches 8x8 Work.
|
# installs silently, relaunches 8x8 Work, and logs everything to
|
||||||
|
# C:\IntuneLogs\8x8Updater_log.txt.
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
|
|
||||||
# Ensure script is running elevated
|
# Ensure script is running elevated
|
||||||
@@ -13,6 +14,29 @@ if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdenti
|
|||||||
|
|
||||||
Add-Type -AssemblyName System.Net.Http
|
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"
|
$workDir = "C:\ProgramData\JCT600_8x8Update"
|
||||||
$flagFile = Join-Path $workDir "8x8_Update_Proceed.flag"
|
$flagFile = Join-Path $workDir "8x8_Update_Proceed.flag"
|
||||||
$htaPromptPath = Join-Path $workDir "Show-8x8Prompt.hta"
|
$htaPromptPath = Join-Path $workDir "Show-8x8Prompt.hta"
|
||||||
@@ -29,12 +53,14 @@ Set-Acl $workDir $acl
|
|||||||
|
|
||||||
if (Test-Path $flagFile) { Remove-Item $flagFile -Force }
|
if (Test-Path $flagFile) { Remove-Item $flagFile -Force }
|
||||||
|
|
||||||
|
Write-Log "========== Starting 8x8 Work Update Script ==========" -Color Cyan
|
||||||
|
|
||||||
try {
|
try {
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
# Step 1: Download 8x8 Setup Installer with Console Progress Bar
|
# 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"
|
$installerUrl = "https://work-desktop-assets.8x8.com/prod-publish/ga/work-64-msi-v8.36.2-3.msi"
|
||||||
Write-Host "[1/4] Downloading 8x8 Work installer..." -ForegroundColor Cyan
|
Write-Log "[1/4] Downloading 8x8 Work installer from $installerUrl..." -Color Cyan
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$httpClient = New-Object System.Net.Http.HttpClient
|
$httpClient = New-Object System.Net.Http.HttpClient
|
||||||
@@ -63,22 +89,23 @@ try {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$outputStream.Close(); $inputStream.Close(); $httpClient.Dispose()
|
$outputStream.Close(); $inputStream.Close(); $httpClient.Dispose()
|
||||||
Write-Host "`nDownload complete: $installerPath" -ForegroundColor Green
|
Write-Host "" # Newline after progress bar
|
||||||
|
Write-Log "Download complete: $installerPath ($([math]::Round($totalBytesRead / 1MB, 2)) MB)" -Color Green
|
||||||
} catch {
|
} catch {
|
||||||
Write-Error "`nFailed to download installer. Error: $_"
|
Write-Log "Failed to download installer. Error: $_" -Color Red
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
# Step 2: Generate Sleep-Safe Wall-Clock HTA Countdown Dialog
|
# Step 2: Generate Sleep-Safe Wall-Clock HTA Countdown Dialog
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
Write-Host "[2/4] Generating sleep-safe unclosable dialog..." -ForegroundColor Cyan
|
Write-Log "[2/4] Generating sleep-safe unclosable dialog..." -Color Cyan
|
||||||
|
|
||||||
$htaContent = @"
|
$htaContent = @"
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>JCT600 IT Support - 8x8 Work Update</title>
|
<title>JCT600 IT Support — 8x8 Work Update</title>
|
||||||
<HTA:APPLICATION
|
<HTA:APPLICATION
|
||||||
ID="o8x8Update"
|
ID="o8x8Update"
|
||||||
APPLICATIONNAME="JCT600 8x8 Work Update"
|
APPLICATIONNAME="JCT600 8x8 Work Update"
|
||||||
@@ -179,7 +206,7 @@ try {
|
|||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body onload="initWindow()">
|
<body onload="initWindow()">
|
||||||
<div class="header">JCT600 - IT SUPPORT</div>
|
<div class="header">JCT600 — IT SUPPORT</div>
|
||||||
<div class="message">
|
<div class="message">
|
||||||
An automatic update for 8x8 Work has been scheduled.<br>
|
An automatic update for 8x8 Work has been scheduled.<br>
|
||||||
Please save active work or click <b>Update Now</b> to begin.
|
Please save active work or click <b>Update Now</b> to begin.
|
||||||
@@ -195,21 +222,19 @@ try {
|
|||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
# Step 3: Detect Active Desktop User & Launch HTA Prompt
|
# Step 3: Detect Active Desktop User & Launch HTA Prompt
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
Write-Host "[3/4] Detecting active console user and launching dialog..." -ForegroundColor Cyan
|
Write-Log "[3/4] Detecting active console user and launching dialog..." -Color Cyan
|
||||||
|
|
||||||
$explorerProc = Get-Process -Name explorer -ErrorAction SilentlyContinue | Select-Object -First 1
|
$explorerProc = Get-Process -Name explorer -ErrorAction SilentlyContinue | Select-Object -First 1
|
||||||
|
|
||||||
if (-not $explorerProc) {
|
if (-not $explorerProc) {
|
||||||
Write-Warning "No active interactive desktop detected. Proceeding directly to update."
|
Write-Log "No active interactive desktop detected. Proceeding directly to update." -Color Yellow
|
||||||
} else {
|
} else {
|
||||||
# Query owner domain\username directly from explorer process
|
|
||||||
$ownerInfo = Get-CimInstance -ClassName Win32_Process -Filter "ProcessId = $($explorerProc.Id)" | Invoke-CimMethod -MethodName GetOwner
|
$ownerInfo = Get-CimInstance -ClassName Win32_Process -Filter "ProcessId = $($explorerProc.Id)" | Invoke-CimMethod -MethodName GetOwner
|
||||||
$activeUser = "$($ownerInfo.Domain)\$($ownerInfo.User)"
|
$activeUser = "$($ownerInfo.Domain)\$($ownerInfo.User)"
|
||||||
Write-Host "Active Desktop User: $activeUser" -ForegroundColor Green
|
Write-Log "Active Desktop User: $activeUser (Session ID: $($explorerProc.SessionId))" -Color Green
|
||||||
|
|
||||||
$taskName = "JCT600_8x8_UpdatePrompt"
|
$taskName = "JCT600_8x8_UpdatePrompt"
|
||||||
|
|
||||||
# Register Scheduled Task targeting the interactive token of the active user
|
|
||||||
$action = New-ScheduledTaskAction -Execute "mshta.exe" -Argument "`"$htaPromptPath`""
|
$action = New-ScheduledTaskAction -Execute "mshta.exe" -Argument "`"$htaPromptPath`""
|
||||||
$trigger = New-ScheduledTaskTrigger -At (Get-Date).AddSeconds(2) -Once
|
$trigger = New-ScheduledTaskTrigger -At (Get-Date).AddSeconds(2) -Once
|
||||||
$principal = New-ScheduledTaskPrincipal -UserId $activeUser -LogonType Interactive -RunLevel Limited
|
$principal = New-ScheduledTaskPrincipal -UserId $activeUser -LogonType Interactive -RunLevel Limited
|
||||||
@@ -218,18 +243,19 @@ try {
|
|||||||
Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Principal $principal -Settings $settings -Force | Out-Null
|
Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Principal $principal -Settings $settings -Force | Out-Null
|
||||||
Start-ScheduledTask -TaskName $taskName | Out-Null
|
Start-ScheduledTask -TaskName $taskName | Out-Null
|
||||||
|
|
||||||
Write-Host "Dialog prompt active. Waiting for user action or 1-hour expiration..." -ForegroundColor Yellow
|
Write-Log "Dialog prompt active. Waiting for user action or 1-hour expiration..." -Color Yellow
|
||||||
while (-not (Test-Path $flagFile)) {
|
while (-not (Test-Path $flagFile)) {
|
||||||
Start-Sleep -Seconds 2
|
Start-Sleep -Seconds 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Write-Log "User action/timeout received. Proceeding with installation." -Color Green
|
||||||
Unregister-ScheduledTask -TaskName $taskName -Confirm:$false -ErrorAction SilentlyContinue
|
Unregister-ScheduledTask -TaskName $taskName -Confirm:$false -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
# Step 4: Close 8x8 Processes & Install Silently
|
# Step 4: Close 8x8 Processes & Install Silently
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
Write-Host "[4/4] Stopping 8x8 processes and installing silently..." -ForegroundColor Cyan
|
Write-Log "[4/4] Stopping active 8x8 processes and installing silently..." -Color Cyan
|
||||||
|
|
||||||
$targetProcesses = Get-Process | Where-Object {
|
$targetProcesses = Get-Process | Where-Object {
|
||||||
$_.ProcessName -like "*8x8*" -or $_.MainWindowTitle -like "*8x8*"
|
$_.ProcessName -like "*8x8*" -or $_.MainWindowTitle -like "*8x8*"
|
||||||
@@ -237,25 +263,29 @@ try {
|
|||||||
|
|
||||||
if ($targetProcesses) {
|
if ($targetProcesses) {
|
||||||
foreach ($proc in $targetProcesses) {
|
foreach ($proc in $targetProcesses) {
|
||||||
|
Write-Log "Stopping process: $($proc.ProcessName) (PID: $($proc.Id))" -Color Yellow
|
||||||
Stop-Process -Id $proc.Id -Force -ErrorAction SilentlyContinue
|
Stop-Process -Id $proc.Id -Force -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
Start-Sleep -Seconds 3
|
Start-Sleep -Seconds 3
|
||||||
}
|
}
|
||||||
|
|
||||||
$msiArgs = "/i `"$installerPath`" /quiet /norestart"
|
$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
|
$installJob = Start-Process msiexec.exe -ArgumentList $msiArgs -Wait -PassThru
|
||||||
|
|
||||||
if ($installJob.ExitCode -ne 0 -and $installJob.ExitCode -ne 3010) {
|
if ($installJob.ExitCode -ne 0 -and $installJob.ExitCode -ne 3010) {
|
||||||
Write-Error "Installation failed with exit code $($installJob.ExitCode)."
|
Write-Log "MSI Installation failed with exit code $($installJob.ExitCode)." -Color Red
|
||||||
exit $installJob.ExitCode
|
exit $installJob.ExitCode
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Installation completed successfully." -ForegroundColor Green
|
Write-Log "MSI Installation completed successfully with ExitCode $($installJob.ExitCode)." -Color Green
|
||||||
|
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
# Step 5: Relaunch 8x8 Work in Active User Session
|
# Step 5: Relaunch 8x8 Work in Active User Session
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
Write-Host "Launching 8x8 Work..." -ForegroundColor Cyan
|
Write-Log "Launching updated 8x8 Work..." -Color Cyan
|
||||||
|
|
||||||
$possiblePaths = @(
|
$possiblePaths = @(
|
||||||
"${env:ProgramFiles}\8x8 Inc\8x8 Work\8x8 Work.exe",
|
"${env:ProgramFiles}\8x8 Inc\8x8 Work\8x8 Work.exe",
|
||||||
@@ -278,17 +308,21 @@ try {
|
|||||||
|
|
||||||
Start-Sleep -Seconds 4
|
Start-Sleep -Seconds 4
|
||||||
Unregister-ScheduledTask -TaskName $launchTask -Confirm:$false -ErrorAction SilentlyContinue
|
Unregister-ScheduledTask -TaskName $launchTask -Confirm:$false -ErrorAction SilentlyContinue
|
||||||
Write-Host "8x8 Work launched successfully." -ForegroundColor Green
|
Write-Log "8x8 Work launched successfully for $activeUser." -Color Green
|
||||||
} else {
|
} else {
|
||||||
Start-Process "explorer.exe" -ArgumentList "`"$exePath`""
|
Start-Process "explorer.exe" -ArgumentList "`"$exePath`""
|
||||||
|
Write-Log "8x8 Work started via explorer.exe fallback." -Color Green
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Write-Warning "Could not locate 8x8 Work executable."
|
Write-Log "Could not locate 8x8 Work executable on disk." -Color Yellow
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} catch {
|
||||||
|
Write-Log "Unexpected script error: $_" -Color Red
|
||||||
} finally {
|
} finally {
|
||||||
Write-Host "Cleaning up temporary files..." -ForegroundColor Gray
|
Write-Log "Cleaning up temporary files..." -Color Gray
|
||||||
if (Test-Path $workDir) {
|
if (Test-Path $workDir) {
|
||||||
Remove-Item $workDir -Recurse -Force -ErrorAction SilentlyContinue
|
Remove-Item $workDir -Recurse -Force -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
|
Write-Log "========== 8x8 Work Update Script Finished ==========" -Color Cyan
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user