@@ -343,6 +343,18 @@ function Install-Standard-Msi([string]$ReleasePage, [string]$Pattern, [string]$F
343
343
Install-Msi $Url
344
344
}
345
345
346
+ # Get user environment variable.
347
+ function Get-UserEnvironment ([string ]$Name )
348
+ {
349
+ return [System.Environment ]::GetEnvironmentVariable($Name , [System.EnvironmentVariableTarget ]::User)
350
+ }
351
+
352
+ # Define user environment variable.
353
+ function Define-UserEnvironment ([string ]$Name , [string ]$Value )
354
+ {
355
+ [System.Environment ]::SetEnvironmentVariable($Name , $Value , [System.EnvironmentVariableTarget ]::User)
356
+ }
357
+
346
358
# Get system-wide environment variable.
347
359
function Get-Environment ([string ]$Name )
348
360
{
@@ -411,3 +423,17 @@ function Search-Path([string]$Name, [string]$Path = $env:Path)
411
423
}
412
424
return $null
413
425
}
426
+
427
+ # Send a WM_SETTINGCHANGE message to all applications
428
+ Add-Type - Namespace Win32 - Name NativeMethods - MemberDefinition @"
429
+ [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
430
+ public static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint Msg, UIntPtr wParam, string lParam, uint fuFlags, uint uTimeout, out UIntPtr lpdwResult);
431
+ "@
432
+
433
+ function Send-SettingChange
434
+ {
435
+ $HWND_BROADCAST = [IntPtr ]0xffff ;
436
+ $WM_SETTINGCHANGE = 0x1a ;
437
+ $result = [UIntPtr ]::Zero
438
+ [void ]([Win32.Nativemethods ]::SendMessageTimeout($HWND_BROADCAST , $WM_SETTINGCHANGE , [UIntPtr ]::Zero, " Environment" , 2 , 5000 , [ref ]$result ))
439
+ }
0 commit comments