Last active
July 21, 2018 22:34
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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