Skip to content

Instantly share code, notes, and snippets.

@antelio
Created June 13, 2018 21:04
Show Gist options
  • Save antelio/8fd0ee4d6552ca13e54c9d5faf5bbc0a to your computer and use it in GitHub Desktop.
Save antelio/8fd0ee4d6552ca13e54c9d5faf5bbc0a to your computer and use it in GitHub Desktop.
if (-not ("win32.nativemethods" -as [type])) {
# import sendmessagetimeout from win32
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
# notify all windows of environment block change
[win32.nativemethods]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE,
[uintptr]::Zero, "Environment", 2, 5000, [ref]$result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment