From 7b3ce8aef6cf8a1c5b53f58b377b102f77c9a7d0 Mon Sep 17 00:00:00 2001 From: 0x574859 Date: Tue, 28 Mar 2023 22:02:55 +0800 Subject: [PATCH 1/3] fix(install-env): Apply env immediately by `SendMessageTimeout` --- install.ps1 | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/install.ps1 b/install.ps1 index 93157a0..5fb488e 100644 --- a/install.ps1 +++ b/install.ps1 @@ -376,6 +376,30 @@ function Get-Env { $EnvRegisterKey.GetValue($name, $null, $RegistryValueOption) } +function Publish-Env { + if (-not ("Win32.NativeMethods" -as [Type])) { + Add-Type -Namespace Win32 -Name NativeMethods -MemberDefinition @" +[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] +public static extern IntPtr SendMessageTimeout( + IntPtr hWnd, uint Msg, UIntPtr wParam, string lParam, + uint fuFlags, uint uTimeout, out UIntPtr lpdwResult); +"@ + } + + $HWND_BROADCAST = [IntPtr] 0xffff; + $WM_SETTINGCHANGE = 0x1a; + $result = [UIntPtr]::Zero + + [Win32.Nativemethods]::SendMessageTimeout($HWND_BROADCAST, + $WM_SETTINGCHANGE, + [UIntPtr]::Zero, + "Environment", + 2, + 5000, + [ref] $result + ) +} + function Write-Env { param( [String] $name, @@ -401,6 +425,7 @@ function Write-Env { [Microsoft.Win32.RegistryValueKind]::String } $EnvRegisterKey.SetValue($name, $val, $RegistryValueKind) + Publish-Env } } From 767adf8ab49647840f72b2d8c6bbb3a559816848 Mon Sep 17 00:00:00 2001 From: 0x574859 Date: Sat, 1 Apr 2023 19:40:55 +0800 Subject: [PATCH 2/3] fix(install-env): Ignore the output of `Publish-Env` --- install.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.ps1 b/install.ps1 index 5fb488e..861a511 100644 --- a/install.ps1 +++ b/install.ps1 @@ -397,7 +397,7 @@ public static extern IntPtr SendMessageTimeout( 2, 5000, [ref] $result - ) + ) | Out-Null } function Write-Env { From 4173ad4124e53b36b4d8672644378523a903a5a4 Mon Sep 17 00:00:00 2001 From: 0x574859 Date: Tue, 11 Apr 2023 18:21:08 +0800 Subject: [PATCH 3/3] fix(install-env): Apply suggestions from code review --- install.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/install.ps1 b/install.ps1 index 861a511..86b6d46 100644 --- a/install.ps1 +++ b/install.ps1 @@ -386,8 +386,8 @@ public static extern IntPtr SendMessageTimeout( "@ } - $HWND_BROADCAST = [IntPtr] 0xffff; - $WM_SETTINGCHANGE = 0x1a; + $HWND_BROADCAST = [IntPtr] 0xffff + $WM_SETTINGCHANGE = 0x1a $result = [UIntPtr]::Zero [Win32.Nativemethods]::SendMessageTimeout($HWND_BROADCAST, @@ -425,8 +425,8 @@ function Write-Env { [Microsoft.Win32.RegistryValueKind]::String } $EnvRegisterKey.SetValue($name, $val, $RegistryValueKind) - Publish-Env } + Publish-Env } function Add-ShimsDirToPath {