Update 8x8_Work_Updater.ps1

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