Skip to content

Instantly share code, notes, and snippets.

@turboBasic
Last active July 21, 2018 22:34
Show Gist options
  • Save turboBasic/49438e8105dc38856862fa4b3b826350 to your computer and use it in GitHub Desktop.
Save turboBasic/49438e8105dc38856862fa4b3b826350 to your computer and use it in GitHub Desktop.
[Send-EnvironmentChangeEvent] :: Broadcasts message to all Windows processes about changes in the Environment variables
function Send-EnvironmentChangeEvent {
DATA ImportWin32Declaration {'
[DllImport("user32.dll", EntryPoint = "SendMessageTimeout")]
public static extern IntPtr SendMessageTimeout(
IntPtr hWnd, UInt Msg, UIntPtr wParam, String lParam, UInt fuFlags, UInt uTimeout, out UIntPtr lpdwResult
);
'}
if (-not ("Win32.NativeMethods" -as [Type])) {
Add-Type -Namespace Win32 -Name NativeMethods -MemberDefinition $ImportWin32Declaration
}
[Win32.NativeMethods]::SendMessageTimeout(
[IntPtr] 0xffff, 0x1a, [UIntPtr]::Zero, "Environment", 2, 5000, [ref] ($result = [UIntPtr]::Zero)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment