Update 8x8_Work_Updater.ps1
This commit is contained in:
+21
-20
@@ -1,8 +1,8 @@
|
|||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
# Script Name: 8x8_Work_Updater.ps1
|
# Script Name: 8x8_Work_Updater.ps1
|
||||||
# Description: Downloads 8x8, launches an interactive JCT600 GUI inside the
|
# Description: Downloads 8x8 with a progress bar, injects a user-session GUI
|
||||||
# active user's desktop session using Explorer process injection,
|
# countdown dialog via HKU RunOnce, waits for user response/timer,
|
||||||
# waits for response/timer, silently installs, and relaunches 8x8.
|
# silently installs, and relaunches 8x8.
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
|
|
||||||
# Ensure script is running elevated
|
# Ensure script is running elevated
|
||||||
@@ -21,7 +21,7 @@ if (-not (Test-Path $workDir)) {
|
|||||||
New-Item -Path $workDir -ItemType Directory -Force | Out-Null
|
New-Item -Path $workDir -ItemType Directory -Force | Out-Null
|
||||||
}
|
}
|
||||||
|
|
||||||
# Ensure standard users have full read/execute permissions to the folder
|
# Ensure standard users have full read/execute permissions to the working folder
|
||||||
$acl = Get-Acl $workDir
|
$acl = Get-Acl $workDir
|
||||||
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("BUILTIN\Users", "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow")
|
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("BUILTIN\Users", "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow")
|
||||||
$acl.AddAccessRule($rule)
|
$acl.AddAccessRule($rule)
|
||||||
@@ -60,7 +60,7 @@ try {
|
|||||||
$totalMB = [math]::Round($totalBytes / 1MB, 2)
|
$totalMB = [math]::Round($totalBytes / 1MB, 2)
|
||||||
$barLength = 30
|
$barLength = 30
|
||||||
$filledLength = [math]::Round(($percent / 100) * $barLength)
|
$filledLength = [math]::Round(($percent / 100) * $barLength)
|
||||||
$bar = ("█" * $filledLength) + ("░" * ($barLength - $filledLength))
|
$bar = ("#" * $filledLength) + ("-" * ($barLength - $filledLength))
|
||||||
|
|
||||||
Write-Host "`rDownloading: [$bar] $percent% ($downloadedMB MB / $totalMB MB)" -NoNewline -ForegroundColor Yellow
|
Write-Host "`rDownloading: [$bar] $percent% ($downloadedMB MB / $totalMB MB)" -NoNewline -ForegroundColor Yellow
|
||||||
}
|
}
|
||||||
@@ -181,34 +181,35 @@ $form.Dispose()
|
|||||||
[System.IO.File]::WriteAllText($guiScript, $guiContent, $utf8NoBom)
|
[System.IO.File]::WriteAllText($guiScript, $guiContent, $utf8NoBom)
|
||||||
|
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
# Step 3: Trigger Interactive GUI in Active Desktop Session
|
# Step 3: Trigger Interactive GUI via Active Desktop Process Execution
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
Write-Host "[3/5] Launching interactive dialog on user desktop..." -ForegroundColor Cyan
|
Write-Host "[3/5] Launching interactive dialog on active user desktop..." -ForegroundColor Cyan
|
||||||
|
|
||||||
$explorerProc = Get-Process -Name explorer -ErrorAction SilentlyContinue | Select-Object -First 1
|
$explorerProc = Get-Process -Name explorer -ErrorAction SilentlyContinue | Select-Object -First 1
|
||||||
|
|
||||||
if (-not $explorerProc) {
|
if (-not $explorerProc) {
|
||||||
Write-Warning "No active desktop session detected. Proceeding directly to update."
|
Write-Warning "No active desktop session detected. Proceeding directly to update."
|
||||||
} else {
|
} else {
|
||||||
# Inject GUI execution trigger into the active user's explorer shell context
|
# Query active user SID from Explorer process
|
||||||
$taskName = "JCT600_8x8_GUI_Task"
|
$userSid = (Get-CimInstance -ClassName Win32_Process -Filter "ProcessId = $($explorerProc.Id)" | Invoke-CimMethod -MethodName GetOwnerSid).Sid
|
||||||
$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-ExecutionPolicy Bypass -WindowStyle Hidden -File `"$guiScript`""
|
|
||||||
|
|
||||||
# Using Interactive logon trigger bypasses Session 0 isolation
|
if ($userSid) {
|
||||||
$trigger = New-ScheduledTaskTrigger -At (Get-Date).AddSeconds(1) -Once
|
# Inject RunOnce command directly into active user registry hive
|
||||||
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -Priority 0
|
$regPath = "Registry::HKEY_USERS\$userSid\Software\Microsoft\Windows\CurrentVersion\RunOnce"
|
||||||
|
$cmdToRun = "powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -File `"$guiScript`""
|
||||||
# Register task under INTERACTIVE user token
|
|
||||||
$task = New-ScheduledTask -Action $action -Trigger $trigger -Settings $settings
|
if (Test-Path $regPath) {
|
||||||
Register-ScheduledTask -TaskName $taskName -InputObject $task -User "INTERACTIVE" -Force | Out-Null
|
Set-ItemProperty -Path $regPath -Name "JCT600_8x8_UpdateGUI" -Value $cmdToRun -Force
|
||||||
Start-ScheduledTask -TaskName $taskName | Out-Null
|
|
||||||
|
# Signal Explorer shell to execute RunOnce entries for active session
|
||||||
|
Start-Process "explorer.exe" -ArgumentList "shell:::{2559a1f3-21d7-11d4-bdaf-00c04f60b9f0}" -ErrorAction SilentlyContinue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Write-Host "Waiting for user dialog response or timer expiration (1 hour max)..." -ForegroundColor Yellow
|
Write-Host "Waiting for user dialog response or timer expiration (1 hour max)..." -ForegroundColor Yellow
|
||||||
while (-not (Test-Path $flagFile)) {
|
while (-not (Test-Path $flagFile)) {
|
||||||
Start-Sleep -Seconds 2
|
Start-Sleep -Seconds 2
|
||||||
}
|
}
|
||||||
|
|
||||||
Unregister-ScheduledTask -TaskName $taskName -Confirm:$false -ErrorAction SilentlyContinue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user