Update 8x8_Work_Updater.ps1
This commit is contained in:
+24
-40
@@ -1,7 +1,7 @@
|
||||
# ==============================================================================
|
||||
# Script Name: 8x8_Work_Updater.ps1
|
||||
# Description: Downloads 8x8, injects a native user-session GUI popup,
|
||||
# waits for completion/override (1-hour countdown),
|
||||
# Description: Downloads 8x8, launches an interactive JCT600 GUI attached to
|
||||
# the active user's session via BUILTIN\Users, waits for response,
|
||||
# silently installs, relaunches 8x8 Work, and cleans up.
|
||||
# ==============================================================================
|
||||
|
||||
@@ -11,6 +11,7 @@ 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"
|
||||
@@ -38,7 +39,7 @@ try {
|
||||
}
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# Step 2: Write User-Session GUI Script
|
||||
# Step 2: Write User-Session GUI Script (BOM-Free UTF-8)
|
||||
# --------------------------------------------------------------------------
|
||||
Write-Host "[2/5] Generating user-session GUI dialog..." -ForegroundColor Cyan
|
||||
|
||||
@@ -146,38 +147,26 @@ $form.Dispose()
|
||||
[System.IO.File]::WriteAllText($guiScript, $guiContent, $utf8NoBom)
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# Step 3: Launch GUI Directly into User Session via Explorer Process Trigger
|
||||
# Step 3: Trigger Interactive GUI in Active User Session via BUILTIN\Users
|
||||
# --------------------------------------------------------------------------
|
||||
Write-Host "[3/5] Launching dialog in active user's desktop session..." -ForegroundColor Cyan
|
||||
|
||||
$explorerProc = Get-Process -Name explorer -ErrorAction SilentlyContinue | Select-Object -First 1
|
||||
$taskName = "JCT600_8x8_Update_UserDialog"
|
||||
$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-ExecutionPolicy Bypass -WindowStyle Hidden -File `"$guiScript`""
|
||||
|
||||
if (-not $explorerProc) {
|
||||
Write-Warning "No active user explorer session found. Proceeding directly to update."
|
||||
} else {
|
||||
# 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
|
||||
# Use BUILTIN\Users group principal for Entra ID / Domain compatibility
|
||||
$principal = New-ScheduledTaskPrincipal -GroupId "BUILTIN\Users" -RunLevel Limited
|
||||
|
||||
# Spawn GUI process directly inside explorer's user context using PowerShell WMI/CIM process creation
|
||||
$cmdToRun = "powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -File `"$guiScript`""
|
||||
Register-ScheduledTask -TaskName $taskName -Action $action -Principal $principal -Force | Out-Null
|
||||
Start-ScheduledTask -TaskName $taskName
|
||||
|
||||
# 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
|
||||
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
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# Step 4: Close Running 8x8 Processes & Install Silently
|
||||
# --------------------------------------------------------------------------
|
||||
@@ -219,20 +208,15 @@ $form.Dispose()
|
||||
$exePath = $possiblePaths | Where-Object { Test-Path $_ } | Select-Object -First 1
|
||||
|
||||
if ($exePath) {
|
||||
if ($explorerProc) {
|
||||
# Run 8x8 Work inside user session to avoid GPU access elevation crashes
|
||||
$launchTask = "JCT600_8x8_AppLaunch"
|
||||
$launchAction = New-ScheduledTaskAction -Execute "$exePath"
|
||||
$launchTrigger = New-ScheduledTaskTrigger -At (Get-Date).AddSeconds(2) -Once
|
||||
$launchPrincipal = New-ScheduledTaskPrincipal -UserId $userSid -LogonType Interactive -RunLevel Limited
|
||||
$launchTask = "JCT600_8x8_AppLaunch"
|
||||
$launchAction = New-ScheduledTaskAction -Execute "$exePath"
|
||||
$launchPrincipal = New-ScheduledTaskPrincipal -GroupId "BUILTIN\Users" -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
|
||||
}
|
||||
Register-ScheduledTask -TaskName $launchTask -Action $launchAction -Principal $launchPrincipal -Force | Out-Null
|
||||
Start-ScheduledTask -TaskName $launchTask
|
||||
Start-Sleep -Seconds 3
|
||||
Unregister-ScheduledTask -TaskName $launchTask -Confirm:$false -ErrorAction SilentlyContinue
|
||||
Write-Host "8x8 Work launched successfully." -ForegroundColor Green
|
||||
} else {
|
||||
Write-Warning "Could not locate 8x8 Work executable."
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user