Last active
August 29, 2015 14:19
-
-
Save Raymai97/ba94871ba9b7abc810a8 to your computer and use it in GitHub Desktop.
Refresh Explorer (apply settings in registry immediately) without restarting Explorer.
Most of the time it works, unless you're using bullheaded OS like Windows 8/8.1...
This file contains 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
Declare Function SHChangeNotify Lib "Shell32.dll" (ByVal wEventID As Int32, _ | |
ByVal uFlags As Int32, ByVal dwItem1 As Int32, ByVal dwItem2 As Int32) As Int32 | |
Sub RefreshExplorer() | |
SHChangeNotify(&H8000000, &H0, 0, 0) | |
Dim CLSID_ShellApplication As New Guid("13709620-C279-11CE-A49E-444553540000") | |
Dim shellApplicationType As Type = Type.GetTypeFromCLSID(CLSID_ShellApplication, True) | |
Dim shellApplication As Object = Activator.CreateInstance(shellApplicationType) | |
Dim windows As Object = shellApplicationType.InvokeMember("Windows", _ | |
System.Reflection.BindingFlags.InvokeMethod, Nothing, shellApplication, New Object() {}) | |
Dim windowsType As Type = windows.[GetType]() | |
Dim count As Object = windowsType.InvokeMember("Count", _ | |
System.Reflection.BindingFlags.GetProperty, Nothing, windows, Nothing) | |
If CInt(count) = 0 Then Exit Sub | |
For i As Integer = 0 To CInt(count) - 1 | |
Dim item As Object = windowsType.InvokeMember("Item", System.Reflection.BindingFlags.InvokeMethod, _ | |
Nothing, windows, New Object() {i}) | |
Dim itemType As Type = item.[GetType]() | |
Dim itemName As String = DirectCast(itemType.InvokeMember("Name", _ | |
System.Reflection.BindingFlags.GetProperty, Nothing, item, Nothing), String) | |
If itemName = "Windows Explorer" Or itemName = "File Explorer" Then | |
itemType.InvokeMember("Refresh", System.Reflection.BindingFlags.InvokeMethod, Nothing, item, Nothing) | |
End If | |
Next | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment