From 330b24641fea85433a4d4dd4161bf6d81d50729c Mon Sep 17 00:00:00 2001 From: Alan Mason <1923621+2Shirt@users.noreply.github.com> Date: Tue, 28 Nov 2017 14:40:43 -0800 Subject: [PATCH] Bugfix: REG_EXPAND_SZ keys now handled correctly --- .bin/Scripts/build_pe.ps1 | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.bin/Scripts/build_pe.ps1 b/.bin/Scripts/build_pe.ps1 index 01209359..5c97b997 100644 --- a/.bin/Scripts/build_pe.ps1 +++ b/.bin/Scripts/build_pe.ps1 @@ -526,10 +526,18 @@ if ($MyInvocation.InvocationName -ne ".") { Start-Process -FilePath $Reg -ArgumentList $ArgumentList -NoNewWindow -Wait # Add tools to path - $RegPath = "HKLM:\WinPE-SYS\ControlSet001\Control\Session Manager\Environment" - $RegKey = Get-ItemProperty -Path $RegPath - $NewValue = "{0};%SystemDrive%\WK\7-Zip;%SystemDrive%\WK\python;%SystemDrive%\WK\wimlib" -f $RegKey.Path - Set-ItemProperty -Path $RegPath -Name "Path" -Value $NewValue -Force | Out-Null + ## .NET code to properly handle REG_EXPAND_SZ values + ## Credit: https://www.sepago.com/blog/2013/08/22/reading-and-writing-regexpandsz-data-with-powershell + ## By: Marius Gawenda + $Hive = [Microsoft.Win32.Registry]::LocalMachine + $RegPath = "WinPE-SYS\ControlSet001\Control\Session Manager\Environment" + $RegKey = $Hive.OpenSubKey($RegPath) + $CurValue = $RegKey.GetValue( + "Path", $false, [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames) + $NewValue = "$CurValue;%SystemDrive%\WK\7-Zip;%SystemDrive%\WK\python;%SystemDrive%\WK\wimlib" + Set-ItemProperty -Path "HKLM:\$RegPath" -Name "Path" -Value $NewValue -Force | Out-Null + $Hive.close() + $RegKey.close() # Replace Notepad ## Currently broken ## @@ -560,5 +568,6 @@ if ($MyInvocation.InvocationName -ne ".") { ## Done ## Pop-Location + Write-Host "`nDone." WKPause "Press Enter to exit... " }