Update 8x8_Work_Updater.ps1

This commit is contained in:
2026-08-25 09:07:51 +01:00
parent fedd15d702
commit 27fe5761f3
+33 -23
View File
@@ -1,8 +1,8 @@
# ==============================================================================
# Script Name: 8x8_Work_Updater.ps1
# Description: Downloads 8x8 with a progress bar, launches an unclosable HTA
# countdown prompt with real-clock wall-time tracking (sleep-safe),
# silently installs, and relaunches 8x8 Work.
# Description: Downloads 8x8 with a progress bar, detects the active interactive
# desktop user dynamically, presents the unclosable HTA countdown
# prompt, installs silently, and relaunches 8x8 Work.
# ==============================================================================
# Ensure script is running elevated
@@ -142,7 +142,6 @@ try {
}
</style>
<script language="javascript">
// Target end time: exactly 1 hour from initial load (survives sleep/standby mode)
var targetTime = new Date().getTime() + (3600 * 1000);
function initWindow() {
@@ -194,28 +193,37 @@ try {
[System.IO.File]::WriteAllText($htaPromptPath, $htaContent, [System.Text.Encoding]::ASCII)
# --------------------------------------------------------------------------
# Step 3: Launch Unclosable Dialog in Active User Session
# Step 3: Detect Active Desktop User & Launch HTA Prompt
# --------------------------------------------------------------------------
Write-Host "[3/4] Launching sleep-safe prompt on logged-in user desktop..." -ForegroundColor Cyan
Write-Host "[3/4] Detecting active console user and launching dialog..." -ForegroundColor Cyan
$loggedUser = (Get-CimInstance Win32_ComputerSystem).UserName
$explorerProc = Get-Process -Name explorer -ErrorAction SilentlyContinue | Select-Object -First 1
if ([string]::IsNullOrWhiteSpace($loggedUser)) {
Write-Warning "No active interactive user detected. Proceeding with silent install."
if (-not $explorerProc) {
Write-Warning "No active interactive desktop detected. Proceeding directly to update."
} else {
# Query owner domain\username directly from explorer process
$ownerInfo = Get-CimInstance -ClassName Win32_Process -Filter "ProcessId = $($explorerProc.Id)" | Invoke-CimMethod -MethodName GetOwner
$activeUser = "$($ownerInfo.Domain)\$($ownerInfo.User)"
Write-Host "Active Desktop User: $activeUser" -ForegroundColor Green
$taskName = "JCT600_8x8_UpdatePrompt"
# Create scheduled task configured to wake/stay active during user session
schtasks.exe /Create /TN $taskName /TR "mshta.exe `"$htaPromptPath`"" /SC ONCE /ST 00:00 /IT /RU "$loggedUser" /F | Out-Null
schtasks.exe /Run /TN $taskName | Out-Null
# Register Scheduled Task targeting the interactive token of the active user
$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)
Write-Host "Prompt active for $loggedUser. Waiting for user action or wall-clock expiration..." -ForegroundColor Yellow
Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Principal $principal -Settings $settings -Force | Out-Null
Start-ScheduledTask -TaskName $taskName | Out-Null
Write-Host "Dialog prompt active. Waiting for user action or 1-hour expiration..." -ForegroundColor Yellow
while (-not (Test-Path $flagFile)) {
Start-Sleep -Seconds 2
}
# Cleanup prompt task
schtasks.exe /Delete /TN $taskName /F 2>&1 | Out-Null
Unregister-ScheduledTask -TaskName $taskName -Confirm:$false -ErrorAction SilentlyContinue
}
# --------------------------------------------------------------------------
@@ -245,7 +253,7 @@ try {
Write-Host "Installation completed successfully." -ForegroundColor Green
# --------------------------------------------------------------------------
# Step 5: Relaunch 8x8 Work via Explorer Shell
# Step 5: Relaunch 8x8 Work in Active User Session
# --------------------------------------------------------------------------
Write-Host "Launching 8x8 Work..." -ForegroundColor Cyan
@@ -259,16 +267,18 @@ try {
$exePath = $possiblePaths | Where-Object { Test-Path $_ } | Select-Object -First 1
if ($exePath) {
if (-not [string]::IsNullOrWhiteSpace($loggedUser)) {
if ($explorerProc -and $activeUser) {
$launchTask = "JCT600_8x8_Launch"
$taskRunCmd = "explorer.exe `"$exePath`""
$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
schtasks.exe /Create /TN $launchTask /TR "$taskRunCmd" /SC ONCE /ST 00:00 /IT /RU "$loggedUser" /F | Out-Null
schtasks.exe /Run /TN $launchTask | Out-Null
Register-ScheduledTask -TaskName $launchTask -Action $launchAction -Trigger $launchTrigger -Principal $launchPrincipal -Force | Out-Null
Start-ScheduledTask -TaskName $launchTask | Out-Null
Start-Sleep -Seconds 5
schtasks.exe /Delete /TN $launchTask /F 2>&1 | Out-Null
Write-Host "8x8 Work launched successfully in user session." -ForegroundColor Green
Start-Sleep -Seconds 4
Unregister-ScheduledTask -TaskName $launchTask -Confirm:$false -ErrorAction SilentlyContinue
Write-Host "8x8 Work launched successfully." -ForegroundColor Green
} else {
Start-Process "explorer.exe" -ArgumentList "`"$exePath`""
}