Update 8x8_Work_Updater.ps1
This commit is contained in:
+29
-117
@@ -1,8 +1,8 @@
|
|||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
# Script Name: 8x8_Work_Updater.ps1
|
# Script Name: 8x8_Work_Updater.ps1
|
||||||
# Description: Downloads 8x8 with a progress bar, uses native WTSQueryUserToken
|
# Description: Downloads 8x8, uses ServiceUI (from internal Gitea) to display
|
||||||
# to display the live countdown GUI directly on the active user's
|
# a 1-hour countdown GUI directly on the active user's desktop,
|
||||||
# screen, silently installs 8x8, and relaunches it.
|
# silently installs 8x8, and relaunches it.
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
|
|
||||||
# Ensure script is running elevated
|
# Ensure script is running elevated
|
||||||
@@ -16,12 +16,14 @@ Add-Type -AssemblyName System.Net.Http
|
|||||||
$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"
|
||||||
|
$serviceUiPath = Join-Path $workDir "ServiceUI.exe"
|
||||||
$installerPath = Join-Path $workDir "8x8_Work_Installer.msi"
|
$installerPath = Join-Path $workDir "8x8_Work_Installer.msi"
|
||||||
|
|
||||||
if (-not (Test-Path $workDir)) {
|
if (-not (Test-Path $workDir)) {
|
||||||
New-Item -Path $workDir -ItemType Directory -Force | Out-Null
|
New-Item -Path $workDir -ItemType Directory -Force | Out-Null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Grant standard users permissions to the directory
|
||||||
$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)
|
||||||
@@ -29,117 +31,20 @@ Set-Acl $workDir $acl
|
|||||||
|
|
||||||
if (Test-Path $flagFile) { Remove-Item $flagFile -Force }
|
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 {
|
try {
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
# Step 1: Download 8x8 Installer with Stream Progress Bar
|
# Step 1: Download 8x8 Installer & ServiceUI from internal Gitea
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
$installerUrl = "https://work-desktop-assets.8x8.com/prod-publish/ga/work-64-msi-v8.35.2-6.msi"
|
$installerUrl = "https://work-desktop-assets.8x8.com/prod-publish/ga/work-64-msi-v8.35.2-6.msi"
|
||||||
Write-Host "[1/5] Downloading 8x8 Work installer..." -ForegroundColor Cyan
|
$serviceUiUrl = "https://gitea.ostroveni.com/JCT/8x8-Work-updater/raw/branch/main/ServiceUI.exe"
|
||||||
|
|
||||||
|
Write-Host "[1/5] Downloading 8x8 Work installer and helper tools..." -ForegroundColor Cyan
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
# Download ServiceUI from internal Gitea
|
||||||
|
Invoke-WebRequest -Uri $serviceUiUrl -OutFile $serviceUiPath -UseBasicParsing
|
||||||
|
|
||||||
|
# Download 8x8 Installer with stream progress bar
|
||||||
$httpClient = New-Object System.Net.Http.HttpClient
|
$httpClient = New-Object System.Net.Http.HttpClient
|
||||||
$response = $httpClient.GetAsync($installerUrl, [System.Net.Http.HttpCompletionOption]::ResponseHeadersRead).Result
|
$response = $httpClient.GetAsync($installerUrl, [System.Net.Http.HttpCompletionOption]::ResponseHeadersRead).Result
|
||||||
if (-not $response.IsSuccessStatusCode) { throw "HTTP Error $($response.StatusCode)" }
|
if (-not $response.IsSuccessStatusCode) { throw "HTTP Error $($response.StatusCode)" }
|
||||||
@@ -168,7 +73,7 @@ try {
|
|||||||
$outputStream.Close(); $inputStream.Close(); $httpClient.Dispose()
|
$outputStream.Close(); $inputStream.Close(); $httpClient.Dispose()
|
||||||
Write-Host "`nDownload complete: $installerPath" -ForegroundColor Green
|
Write-Host "`nDownload complete: $installerPath" -ForegroundColor Green
|
||||||
} catch {
|
} catch {
|
||||||
Write-Error "`nFailed to download installer. Error: $_"
|
Write-Error "`nFailed to download installer or tools. Error: $_"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,20 +186,22 @@ $form.Dispose()
|
|||||||
[System.IO.File]::WriteAllText($guiScript, $guiContent, $utf8NoBom)
|
[System.IO.File]::WriteAllText($guiScript, $guiContent, $utf8NoBom)
|
||||||
|
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
# Step 3: Launch Interactive GUI Directly in User Session
|
# Step 3: Launch GUI via ServiceUI Directly into Active User's Session
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
Write-Host "[3/5] Launching interactive dialog on active user desktop..." -ForegroundColor Cyan
|
Write-Host "[3/5] Launching interactive dialog on active user desktop via ServiceUI..." -ForegroundColor Cyan
|
||||||
|
|
||||||
$launchCmd = "powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -File `"$guiScript`""
|
$explorerProc = Get-Process -Name explorer -ErrorAction SilentlyContinue | Select-Object -First 1
|
||||||
$launched = [WTSSessionBridge]::LaunchInActiveSession($launchCmd)
|
|
||||||
|
if (-not $explorerProc) {
|
||||||
|
Write-Warning "No active desktop session detected. Proceeding directly to update."
|
||||||
|
} else {
|
||||||
|
$serviceUiArgs = "-process:explorer.exe powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -File `"$guiScript`""
|
||||||
|
Start-Process -FilePath $serviceUiPath -ArgumentList $serviceUiArgs
|
||||||
|
|
||||||
if ($launched) {
|
|
||||||
Write-Host "Dialog displayed on user screen. Waiting for response or 1-hour expiration..." -ForegroundColor Yellow
|
Write-Host "Dialog displayed on user screen. Waiting for response or 1-hour expiration..." -ForegroundColor Yellow
|
||||||
while (-not (Test-Path $flagFile)) {
|
while (-not (Test-Path $flagFile)) {
|
||||||
Start-Sleep -Seconds 2
|
Start-Sleep -Seconds 2
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
Write-Warning "No active interactive console session found. Proceeding directly to update."
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
@@ -338,8 +245,13 @@ $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) {
|
||||||
[WTSSessionBridge]::LaunchInActiveSession("`"$exePath`"") | Out-Null
|
if ($explorerProc) {
|
||||||
|
$launchArgs = "-process:explorer.exe `"$exePath`""
|
||||||
|
Start-Process -FilePath $serviceUiPath -ArgumentList $launchArgs
|
||||||
Write-Host "8x8 Work launched successfully in user context." -ForegroundColor Green
|
Write-Host "8x8 Work launched successfully in user context." -ForegroundColor Green
|
||||||
|
} else {
|
||||||
|
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