Update 8x8_Work_Updater.ps1
This commit is contained in:
+24
-40
@@ -1,7 +1,7 @@
|
|||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
# Script Name: 8x8_Work_Updater.ps1
|
# Script Name: 8x8_Work_Updater.ps1
|
||||||
# Description: Downloads 8x8, injects a native user-session GUI popup,
|
# Description: Downloads 8x8, launches an interactive JCT600 GUI attached to
|
||||||
# waits for completion/override (1-hour countdown),
|
# the active user's session via BUILTIN\Users, waits for response,
|
||||||
# silently installs, relaunches 8x8 Work, and cleans up.
|
# silently installs, relaunches 8x8 Work, and cleans up.
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
|
|
||||||
@@ -11,6 +11,7 @@ if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdenti
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Use C:\ProgramData\ so standard users have full read/execute access
|
||||||
$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"
|
||||||
$guiScript = Join-Path $workDir "Show-8x8UserGui.ps1"
|
$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
|
Write-Host "[2/5] Generating user-session GUI dialog..." -ForegroundColor Cyan
|
||||||
|
|
||||||
@@ -146,38 +147,26 @@ $form.Dispose()
|
|||||||
[System.IO.File]::WriteAllText($guiScript, $guiContent, $utf8NoBom)
|
[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
|
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) {
|
# Use BUILTIN\Users group principal for Entra ID / Domain compatibility
|
||||||
Write-Warning "No active user explorer session found. Proceeding directly to update."
|
$principal = New-ScheduledTaskPrincipal -GroupId "BUILTIN\Users" -RunLevel Limited
|
||||||
} 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
|
|
||||||
|
|
||||||
# Spawn GUI process directly inside explorer's user context using PowerShell WMI/CIM process creation
|
Register-ScheduledTask -TaskName $taskName -Action $action -Principal $principal -Force | Out-Null
|
||||||
$cmdToRun = "powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -File `"$guiScript`""
|
Start-ScheduledTask -TaskName $taskName
|
||||||
|
|
||||||
# Fallback to direct process invocation if user session is active
|
Write-Host "Waiting for user dialog response or timer expiration (1 hour max)..." -ForegroundColor Yellow
|
||||||
$taskName = "JCT600_8x8_Update_UserDialog"
|
while (-not (Test-Path $flagFile)) {
|
||||||
$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-ExecutionPolicy Bypass -WindowStyle Hidden -File `"$guiScript`""
|
Start-Sleep -Seconds 2
|
||||||
$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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Unregister-ScheduledTask -TaskName $taskName -Confirm:$false -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
# Step 4: Close Running 8x8 Processes & Install Silently
|
# Step 4: Close Running 8x8 Processes & Install Silently
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
@@ -219,20 +208,15 @@ $form.Dispose()
|
|||||||
$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 ($explorerProc) {
|
$launchTask = "JCT600_8x8_AppLaunch"
|
||||||
# Run 8x8 Work inside user session to avoid GPU access elevation crashes
|
$launchAction = New-ScheduledTaskAction -Execute "$exePath"
|
||||||
$launchTask = "JCT600_8x8_AppLaunch"
|
$launchPrincipal = New-ScheduledTaskPrincipal -GroupId "BUILTIN\Users" -RunLevel Limited
|
||||||
$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
|
Register-ScheduledTask -TaskName $launchTask -Action $launchAction -Principal $launchPrincipal -Force | Out-Null
|
||||||
Start-Sleep -Seconds 4
|
Start-ScheduledTask -TaskName $launchTask
|
||||||
Unregister-ScheduledTask -TaskName $launchTask -Confirm:$false -ErrorAction SilentlyContinue
|
Start-Sleep -Seconds 3
|
||||||
Write-Host "8x8 Work launched successfully." -ForegroundColor Green
|
Unregister-ScheduledTask -TaskName $launchTask -Confirm:$false -ErrorAction SilentlyContinue
|
||||||
} else {
|
Write-Host "8x8 Work launched successfully." -ForegroundColor Green
|
||||||
Start-Process -FilePath $exePath
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Write-Warning "Could not locate 8x8 Work executable."
|
Write-Warning "Could not locate 8x8 Work executable."
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user