Click here to Skip to main content
Click here to Skip to main content

Tagged as

Change Registry Settings and Broadcast Changes (Refresh Desktop and Windows Explorer)

, 2 Jun 2011
Rate this:
Please Sign up or sign in to vote.
[solved]

Hello all. I found a solution that can change Registry settings and broadcast the changes to the Desktop and Windows Explorer. Here is the code for changing Show/Hide File Extension:

Private Shared Sub HideFilesExtension(ByVal Hide As Boolean)
    Dim root As String = "Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
    Dim HideFileExt As RegistryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(root, True)
    HideFileExt.SetValue("HideFileExt", IIf(Hide, 1, 0))
    HideFileExt.Close()
    mhkwins.commons.RefreshExplorer()
End Sub

Here is the code to refresh the Desktop and Window Explorer:

Private Declare Function SHChangeNotify Lib "Shell32.dll" (ByVal wEventID As Int32, _
        ByVal uFlags As Int32, ByVal dwItem1 As Int32, ByVal dwItem2 As Int32) As Int32
  Public Shared Sub RefreshExplorer()
    Call Shell("explorer /select," & "C:\DATA\", AppWinStyle.NormalFocus)
    Threading.Thread.Sleep(3000)
    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]()
      ' only refresh windows explorers       
      Dim itemName As String = DirectCast(itemType.InvokeMember("Name", _
          System.Reflection.BindingFlags.GetProperty, Nothing, item, Nothing), String)
      'MsgBox(itemName)
      If itemName = "Windows Explorer" Then
        itemType.InvokeMember("Refresh", System.Reflection.BindingFlags.InvokeMethod, Nothing, item, Nothing)
      End If
    Next
End Sub

That's all.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

NIkradsystem

United States United States
No Biography provided

Comments and Discussions

 
GeneralMy vote of 5 Pinmemberytfrdfiw3-Sep-12 19:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 2 Jun 2011
Article Copyright 2011 by NIkradsystem
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid