Update 8x8_Work_Updater.ps1

This commit is contained in:
2026-07-29 17:11:21 +01:00
parent cfd5589796
commit 5070bc964f
+36 -42
View File
@@ -1,7 +1,7 @@
# ==============================================================================
# Script Name: 8x8_Work_Updater.ps1
# Description: Downloads 8x8, launches an interactive JCT600 GUI attached to
# the active user's desktop via schtasks /IT, waits for response,
# Description: Downloads 8x8, injects a native user-session GUI popup,
# waits for completion/override (1-hour countdown),
# silently installs, relaunches 8x8 Work, and cleans up.
# ==============================================================================
@@ -11,18 +11,14 @@ if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdenti
exit 1
}
# Use C:\ProgramData\ so standard users have full read/execute access
$workDir = "C:\ProgramData\JCT600_8x8Update"
$flagFile = Join-Path $workDir "8x8_Update_Proceed.flag"
$guiScript = Join-Path $workDir "Show-8x8UserGui.ps1"
$vbsScript = Join-Path $workDir "LaunchGuiHidden.vbs"
$taskName = "JCT600_8x8_Update_Notification"
if (-not (Test-Path $workDir)) {
New-Item -Path $workDir -ItemType Directory -Force | Out-Null
}
# Clean stale flag file
if (Test-Path $flagFile) { Remove-Item $flagFile -Force }
try {
@@ -42,9 +38,9 @@ try {
}
# --------------------------------------------------------------------------
# Step 2: Write User GUI & Zero-Console VBS Launcher
# Step 2: Write User-Session GUI Script
# --------------------------------------------------------------------------
Write-Host "[2/5] Generating user-session GUI and hidden launcher..." -ForegroundColor Cyan
Write-Host "[2/5] Generating user-session GUI dialog..." -ForegroundColor Cyan
$guiContent = @'
Add-Type -AssemblyName System.Windows.Forms
@@ -146,44 +142,40 @@ $timer.Dispose()
$form.Dispose()
'@
# Write UTF8 without BOM
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
[System.IO.File]::WriteAllText($guiScript, $guiContent, $utf8NoBom)
# VBScript Wrapper (ASCII)
$vbsContent = @"
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -File ""$guiScript""", 0, False
"@
[System.IO.File]::WriteAllText($vbsScript, $vbsContent, [System.Text.Encoding]::ASCII)
# --------------------------------------------------------------------------
# Step 3: Trigger Interactive GUI Attached to User Desktop WindowStation
# Step 3: Launch GUI Directly into User Session via Explorer Process Trigger
# --------------------------------------------------------------------------
Write-Host "[3/5] Launching dialog in active user's desktop session..." -ForegroundColor Cyan
$loggedUser = (Get-CimInstance -ClassName Win32_ComputerSystem).UserName
if ([string]::IsNullOrEmpty($loggedUser)) {
$explorerProc = Get-Process -Name explorer -ErrorAction SilentlyContinue | Select-Object -First 1
if ($explorerProc) {
$loggedUser = (Get-CimInstance -ClassName Win32_Process -Filter "ProcessId = $($explorerProc.Id)" | Invoke-CimMethod -MethodName GetOwner).User
}
}
$explorerProc = Get-Process -Name explorer -ErrorAction SilentlyContinue | Select-Object -First 1
if ([string]::IsNullOrEmpty($loggedUser)) {
Write-Warning "No active interactive user detected. Proceeding directly to silent update."
if (-not $explorerProc) {
Write-Warning "No active user explorer session found. Proceeding directly to update."
} else {
Write-Host "Detected active user: $loggedUser" -ForegroundColor Green
# Query active user SID from Explorer process
$userSid = (Get-CimInstance -ClassName Win32_Process -Filter "ProcessId = $($explorerProc.Id)" | Invoke-CimMethod -MethodName GetOwnerSid).Sid
Write-Host "Active Desktop SID: $userSid" -ForegroundColor Green
# Register task using schtasks.exe /IT to force GUI attachment to active screen station
$trCommand = "wscript.exe `"$vbsScript`""
& schtasks.exe /Create /TN $taskName /TR $trCommand /SC ONCE /ST 00:00 /RU $loggedUser /IT /F | Out-Null
& schtasks.exe /Run /TN $taskName | Out-Null
# Spawn GUI process directly inside explorer's user context using PowerShell WMI/CIM process creation
$cmdToRun = "powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -File `"$guiScript`""
# Fallback to direct process invocation if user session is active
$taskName = "JCT600_8x8_Update_UserDialog"
$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-ExecutionPolicy Bypass -WindowStyle Hidden -File `"$guiScript`""
$trigger = New-ScheduledTaskTrigger -At (Get-Date).AddSeconds(2) -Once
$principal = New-ScheduledTaskPrincipal -UserId $userSid -LogonType Interactive -RunLevel Limited
Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Principal $principal -Force | Out-Null
Write-Host "Waiting for user dialog response or timer expiration (1 hour max)..." -ForegroundColor Yellow
while (-not (Test-Path $flagFile)) {
Start-Sleep -Seconds 2
}
Unregister-ScheduledTask -TaskName $taskName -Confirm:$false -ErrorAction SilentlyContinue
}
# --------------------------------------------------------------------------
@@ -213,9 +205,9 @@ WshShell.Run "powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -File "
Write-Host "Installation completed successfully." -ForegroundColor Green
# --------------------------------------------------------------------------
# Step 5: Launch 8x8 Work in User Desktop Session
# Step 5: Launch 8x8 Work
# --------------------------------------------------------------------------
Write-Host "[5/5] Launching 8x8 Work in user session..." -ForegroundColor Cyan
Write-Host "[5/5] Launching 8x8 Work..." -ForegroundColor Cyan
$possiblePaths = @(
"${env:ProgramFiles}\8x8 Inc\8x8 Work\8x8 Work.exe",
@@ -227,13 +219,17 @@ WshShell.Run "powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -File "
$exePath = $possiblePaths | Where-Object { Test-Path $_ } | Select-Object -First 1
if ($exePath) {
if (-not [string]::IsNullOrEmpty($loggedUser)) {
if ($explorerProc) {
# Run 8x8 Work inside user session to avoid GPU access elevation crashes
$launchTask = "JCT600_8x8_AppLaunch"
& schtasks.exe /Create /TN $launchTask /TR "`"$exePath`"" /SC ONCE /ST 00:00 /RU $loggedUser /IT /F | Out-Null
& schtasks.exe /Run /TN $launchTask | Out-Null
Start-Sleep -Seconds 3
& schtasks.exe /Delete /TN $launchTask /F | Out-Null
Write-Host "8x8 Work launched successfully for $loggedUser." -ForegroundColor Green
$launchAction = New-ScheduledTaskAction -Execute "$exePath"
$launchTrigger = New-ScheduledTaskTrigger -At (Get-Date).AddSeconds(2) -Once
$launchPrincipal = New-ScheduledTaskPrincipal -UserId $userSid -LogonType Interactive -RunLevel Limited
Register-ScheduledTask -TaskName $launchTask -Action $launchAction -Trigger $launchTrigger -Principal $launchPrincipal -Force | Out-Null
Start-Sleep -Seconds 4
Unregister-ScheduledTask -TaskName $launchTask -Confirm:$false -ErrorAction SilentlyContinue
Write-Host "8x8 Work launched successfully." -ForegroundColor Green
} else {
Start-Process -FilePath $exePath
}
@@ -245,9 +241,7 @@ WshShell.Run "powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -File "
# --------------------------------------------------------------------------
# Mandatory Cleanup
# --------------------------------------------------------------------------
Write-Host "Cleaning up scheduled task and temporary files..." -ForegroundColor Gray
& schtasks.exe /Delete /TN $taskName /F 2>$null | Out-Null
Write-Host "Cleaning up temporary files..." -ForegroundColor Gray
if (Test-Path $workDir) {
Remove-Item $workDir -Recurse -Force -ErrorAction SilentlyContinue
}