11-16-2010
Downloads: 560
File size: 1.1kB
Views: 3,208
Embed
 |
Refresh Explorer |
- function Refresh-Explorer {
- $code = @'
- private static readonly IntPtr HWND_BROADCAST = new IntPtr(0xffff);
- private const int WM_SETTINGCHANGE = 0x1a;
- private const int SMTO_ABORTIFHUNG = 0x0002;
-
-
- [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError=true, CharSet=CharSet.Auto)]
- static extern bool SendNotifyMessage(IntPtr hWnd, uint Msg, UIntPtr wParam,
- IntPtr lParam);
-
- [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
- private static extern IntPtr SendMessageTimeout ( IntPtr hWnd, int Msg, IntPtr wParam, string lParam, uint fuFlags, uint uTimeout, IntPtr lpdwResult );
-
-
- [System.Runtime.InteropServices.DllImport("Shell32.dll")]
- private static extern int SHChangeNotify(int eventId, int flags, IntPtr item1, IntPtr item2);
-
-
- public static void Refresh() {
- SHChangeNotify(0x8000000, 0x1000, IntPtr.Zero, IntPtr.Zero);
- SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, IntPtr.Zero, null, SMTO_ABORTIFHUNG, 100, IntPtr.Zero);
- }
- '@
-
- Add-Type -MemberDefinition $code -Namespace MyWinAPI -Name Explorer
- [MyWinAPI.Explorer]::Refresh()
- }
creates a function called Refresh-Explorer which calls native API functions to make explorer refresh its settings. So whenever you have changed registry values or other configuration details and want to inform explorer of these, use this function which avoids a reboot.