Guest User

Untitled

a guest
Jul 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. function Send-EnvironmentChangeEvent {
  2.  
  3. @"
  4. [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
  5. public static extern IntPtr SendMessageTimeout(
  6. IntPtr hWnd, uint Msg, UIntPtr wParam, string lParam, uint fuFlags, uint uTimeout, out UIntPtr lpdwResult
  7. );
  8. "@ | Set-Variable ImportWin32Declaration
  9.  
  10. if (-not ("Win32.NativeMethods" -as [Type])) {
  11. Add-Type -Namespace Win32 -Name NativeMethods -MemberDefinition $ImportWin32Declaration
  12. }
  13.  
  14. $HWND_BROADCAST = [System.IntPtr] 0xffff
  15. $WM_SETTINGCHANGE = 0x1a
  16. $result = [System.UIntPtr]::Zero
  17.  
  18. [Win32.NativeMethods]::SendMessageTimeout(
  19. $HWND_BROADCAST,
  20. $WM_SETTINGCHANGE,
  21. [System.UIntPtr]::Zero,
  22. "Environment",
  23. 2,
  24. 5000,
  25. [ref] $result
  26. )
  27. }
Add Comment
Please, Sign In to add comment