diff --git a/8x8_Work_Updater.ps1 b/8x8_Work_Updater.ps1 index 7285fb7..4fc9744 100644 --- a/8x8_Work_Updater.ps1 +++ b/8x8_Work_Updater.ps1 @@ -1,8 +1,8 @@ # ============================================================================== # Script Name: 8x8_Work_Updater.ps1 -# Description: Downloads 8x8, uses ServiceUI to display a live countdown GUI -# directly inside the active user's desktop session, silently -# installs 8x8, and relaunches the application. +# Description: Downloads 8x8 with a progress bar, uses native WTSQueryUserToken +# to display the live countdown GUI directly on the active user's +# screen, silently installs 8x8, and relaunches it. # ============================================================================== # Ensure script is running elevated @@ -16,14 +16,12 @@ Add-Type -AssemblyName System.Net.Http $workDir = "C:\ProgramData\JCT600_8x8Update" $flagFile = Join-Path $workDir "8x8_Update_Proceed.flag" $guiScript = Join-Path $workDir "Show-8x8UserGui.ps1" -$serviceUiPath = Join-Path $workDir "ServiceUI.exe" $installerPath = Join-Path $workDir "8x8_Work_Installer.msi" if (-not (Test-Path $workDir)) { New-Item -Path $workDir -ItemType Directory -Force | Out-Null } -# Ensure standard users have permissions to read/execute from this directory $acl = Get-Acl $workDir $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("BUILTIN\Users", "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow") $acl.AddAccessRule($rule) @@ -31,21 +29,117 @@ Set-Acl $workDir $acl if (Test-Path $flagFile) { Remove-Item $flagFile -Force } +# ------------------------------------------------------------------------------ +# Native C# WTS Session Launcher (Bypasses Session 0 Isolation) +# ------------------------------------------------------------------------------ +$WTSLauncherCode = @" +using System; +using System.Runtime.InteropServices; + +public class WTSSessionBridge +{ + [DllImport("wtsapi32.dll", SetLastError = true)] + private static extern bool WTSQueryUserToken(uint sessionId, out IntPtr phToken); + + [DllImport("kernel32.dll")] + private static extern uint WTSGetActiveConsoleSessionId(); + + [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Auto)] + private static extern bool CreateProcessAsUser( + IntPtr hToken, + string lpApplicationName, + string lpCommandLine, + IntPtr lpProcessAttributes, + IntPtr lpThreadAttributes, + bool bInheritHandles, + uint dwCreationFlags, + IntPtr lpEnvironment, + string lpCurrentDirectory, + ref STARTUPINFO lpStartupInfo, + out PROCESS_INFORMATION lpProcessInformation + ); + + [DllImport("kernel32.dll", SetLastError = true)] + private static extern bool CloseHandle(IntPtr hObject); + + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + private struct STARTUPINFO + { + public int cb; + public string lpReserved; + public string lpDesktop; + public string lpTitle; + public int dwX; + public int dwY; + public int dwXSize; + public int dwYSize; + public int dwXCountChars; + public int dwYCountChars; + public int dwFillAttribute; + public int dwFlags; + public short wShowWindow; + public short cbReserved2; + public IntPtr lpReserved2; + public IntPtr hStdInput; + public IntPtr hStdOutput; + public IntPtr hStdError; + } + + [StructLayout(LayoutKind.Sequential)] + private struct PROCESS_INFORMATION + { + public IntPtr hProcess; + public IntPtr hThread; + public int dwProcessId; + public int dwThreadId; + } + + public static bool LaunchInActiveSession(string cmd) + { + uint activeSessionId = WTSGetActiveConsoleSessionId(); + if (activeSessionId == 0xFFFFFFFF) return false; + + IntPtr userToken; + if (!WTSQueryUserToken(activeSessionId, out userToken)) return false; + + STARTUPINFO si = new STARTUPINFO(); + si.cb = Marshal.SizeOf(si); + si.lpDesktop = @"winsta0\default"; + + PROCESS_INFORMATION pi = new PROCESS_INFORMATION(); + bool success = CreateProcessAsUser( + userToken, + null, + cmd, + IntPtr.Zero, + IntPtr.Zero, + false, + 0x00000010, // CREATE_NEW_CONSOLE + IntPtr.Zero, + null, + ref si, + out pi + ); + + if (pi.hProcess != IntPtr.Zero) CloseHandle(pi.hProcess); + if (pi.hThread != IntPtr.Zero) CloseHandle(pi.hThread); + if (userToken != IntPtr.Zero) CloseHandle(userToken); + + return success; + } +} +"@ + +Add-Type -TypeDefinition $WTSLauncherCode -ErrorAction SilentlyContinue + try { # -------------------------------------------------------------------------- - # Step 1: Download 8x8 Installer & ServiceUI Tool + # Step 1: Download 8x8 Installer with Stream Progress Bar # -------------------------------------------------------------------------- $installerUrl = "https://work-desktop-assets.8x8.com/prod-publish/ga/work-64-msi-v8.35.2-6.msi" - # Portable ServiceUI x64 direct binary - $serviceUiUrl = "https://raw.githubusercontent.com/asheroto/ServiceUI/main/ServiceUI_x64.exe" - - Write-Host "[1/5] Downloading 8x8 Work installer and helper tools..." -ForegroundColor Cyan + Write-Host "[1/5] Downloading 8x8 Work installer..." -ForegroundColor Cyan try { - # Download ServiceUI - Invoke-WebRequest -Uri $serviceUiUrl -OutFile $serviceUiPath -UseBasicParsing - - # Download 8x8 Installer with stream progress bar $httpClient = New-Object System.Net.Http.HttpClient $response = $httpClient.GetAsync($installerUrl, [System.Net.Http.HttpCompletionOption]::ResponseHeadersRead).Result if (-not $response.IsSuccessStatusCode) { throw "HTTP Error $($response.StatusCode)" } @@ -74,12 +168,12 @@ try { $outputStream.Close(); $inputStream.Close(); $httpClient.Dispose() Write-Host "`nDownload complete: $installerPath" -ForegroundColor Green } catch { - Write-Error "`nFailed to download installer or tools. Error: $_" + Write-Error "`nFailed to download installer. Error: $_" exit 1 } # -------------------------------------------------------------------------- - # 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 script..." -ForegroundColor Cyan @@ -187,23 +281,20 @@ $form.Dispose() [System.IO.File]::WriteAllText($guiScript, $guiContent, $utf8NoBom) # -------------------------------------------------------------------------- - # Step 3: Launch GUI via ServiceUI Directly into Active User's Session + # Step 3: Launch Interactive GUI Directly in User Session # -------------------------------------------------------------------------- - Write-Host "[3/5] Launching interactive dialog on active user desktop via ServiceUI..." -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 + $launchCmd = "powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -File `"$guiScript`"" + $launched = [WTSSessionBridge]::LaunchInActiveSession($launchCmd) - if (-not $explorerProc) { - Write-Warning "No active desktop session detected. Proceeding directly to update." - } else { - # ServiceUI attaches the process directly into explorer.exe's interactive window station - $serviceUiArgs = "-process:explorer.exe powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -File `"$guiScript`"" - Start-Process -FilePath $serviceUiPath -ArgumentList $serviceUiArgs - - Write-Host "Dialog displayed on user screen. Waiting for user response or 1-hour expiration..." -ForegroundColor Yellow + if ($launched) { + Write-Host "Dialog displayed on user screen. Waiting for response or 1-hour expiration..." -ForegroundColor Yellow while (-not (Test-Path $flagFile)) { Start-Sleep -Seconds 2 } + } else { + Write-Warning "No active interactive console session found. Proceeding directly to update." } # -------------------------------------------------------------------------- @@ -247,13 +338,8 @@ $form.Dispose() $exePath = $possiblePaths | Where-Object { Test-Path $_ } | Select-Object -First 1 if ($exePath) { - if ($explorerProc) { - $launchArgs = "-process:explorer.exe `"$exePath`"" - Start-Process -FilePath $serviceUiPath -ArgumentList $launchArgs - Write-Host "8x8 Work launched successfully in user context." -ForegroundColor Green - } else { - Start-Process -FilePath $exePath - } + [WTSSessionBridge]::LaunchInActiveSession("`"$exePath`"") | Out-Null + Write-Host "8x8 Work launched successfully in user context." -ForegroundColor Green } else { Write-Warning "Could not locate 8x8 Work executable." }