From 97f2ad6e98b5f9f4f546f873ec9012a499552917 Mon Sep 17 00:00:00 2001 From: Omar <90123670+mewclouds@users.noreply.github.com> Date: Mon, 3 Aug 2026 20:10:49 -0400 Subject: [PATCH] Fix windev prerelease version during elevation (#4908) * Fix prerelease elevation cleanup * Support restricted PowerShell in windev * Use current PowerShell engine in windev --- scripts/main.ps1 | 24 ++++++++++++++++++++++++ windev.ps1 | 10 ++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index e3f14dec..4d050052 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -517,7 +517,31 @@ $sync["WPFWin11ISOCleanResetButton"].Add_Click({ Invoke-WinUtilISOCleanAndReset }) +function Remove-WinUtilTempScript { + <# + .SYNOPSIS + Removes the temporary script downloaded by windev.ps1. + + .DESCRIPTION + Deletes the current script only when it is a winutil-*.ps1 file in + the system temporary directory. This preserves normal file-backed + and in-memory WinUtil launches. + #> + + $scriptPath = $PSCommandPath + $tempPath = [IO.Path]::GetFullPath([IO.Path]::GetTempPath()).TrimEnd('\') + + if ( + $scriptPath -and + [IO.Path]::GetDirectoryName($scriptPath) -eq $tempPath -and + [IO.Path]::GetFileName($scriptPath) -like 'winutil-*.ps1' + ) { + Remove-Item -LiteralPath $scriptPath -Force -ErrorAction SilentlyContinue + } +} + # ────────────────────────────────────────────────────────────────────────────── $sync["Form"].ShowDialog() | out-null +Remove-WinUtilTempScript Stop-Transcript diff --git a/windev.ps1 b/windev.ps1 index b6429fce..99ff2fab 100644 --- a/windev.ps1 +++ b/windev.ps1 @@ -1,5 +1,11 @@ # Runs the pre-release version of winutil $latestTag = (Invoke-RestMethod https://api.github.com/repos/ChrisTitusTech/winutil/tags).Name | Select-Object -First 1 -$script = Invoke-RestMethod -Uri https://github.com/ChrisTitusTech/winutil/releases/download/$latestTag/winutil.ps1 -Invoke-Command -ScriptBlock ([scriptblock]::Create($script)) -ErrorAction Stop +$uri = "https://github.com/ChrisTitusTech/winutil/releases/download/$latestTag/winutil.ps1" +$scriptPath = Join-Path $env:TEMP "winutil-$latestTag.ps1" + +Invoke-WebRequest -Uri $uri -OutFile $scriptPath -UseBasicParsing -ErrorAction Stop + +$executable = if ($PSVersionTable.PSEdition -eq 'Core') { 'pwsh.exe' } else { 'powershell.exe' } +$currentPowerShell = Join-Path $PSHOME $executable +& $currentPowerShell -ExecutionPolicy Bypass -NoProfile -File $scriptPath