• 0

[C#] Windows Explorer Refresh


Question

I've made a simple C# application that changes a registry value. After it has changed the value, I want it to tell Windows to refresh the explorer so that the change takes effect without me having to manually refresh explorer. Can anyone suggest how to properly tell Windows to refresh the explorer? If possible, can you provide a code sample? Thanks.

Link to comment
https://www.neowin.net/forum/topic/573670-c-windows-explorer-refresh/
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Do you need to refresh icons or what?

If it's icons, then use SHChangeNotify() function.

pinvoke.net - SHChangeNotify.

Contains signature for function and enums (HChangeNotifyEventID, HChangeNotifyFlags).

Then you need to execute:

SHChangeNotify(HChangeNotifyEventID.SHCNE_ASSOCCHANGED, HChangeNotifyFlags.SHCNF_IDLIST, IntPtr.Zero, IntPtr.Zero);

  • 0

Thanks for the info. I have already read about SHChangeNotify() before while searching for answers before posting. To answer your question, I need to referesh icons/folders (essentially, I need to referesh any open explorer windows completely). My main problem is that I don't know what namespaces/classes to import into the project so I can use SHChangeNotify. Any thoughts?

  • 0

Thanks for all the help. It now works almost everytime, but sometimes the explorer window(s) still doesn't refresh. I'm now using these 3 SHChangeNotify calls. The last one seemed to help more than the others, but when I took the others away, nothing happened. Out of curiousity, is there any other way to refresh the explorer? I keep reading about invalidating the desktop or something to that extent? Thanks.

//Alert the system of the change --> Explorer Refresh
SHChangeNotify(HChangeNotifyEventID.SHCNE_ALLEVENTS, HChangeNotifyFlags.SHCNF_DWORD, IntPtr.Zero, IntPtr.Zero);
SHChangeNotify(HChangeNotifyEventID.SHCNE_ASSOCCHANGED, HChangeNotifyFlags.SHCNF_IDLIST, IntPtr.Zero, IntPtr.Zero);
SHChangeNotify(HChangeNotifyEventID.SHCNE_UPDATEDIR, HChangeNotifyFlags.SHCNF_IDLIST, IntPtr.Zero, IntPtr.Zero);

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

  • Recent Achievements

    • First Post
      Fuzz_c earned a badge
      First Post
    • First Post
      TIGOSS earned a badge
      First Post
    • Week One Done
      slackerzz earned a badge
      Week One Done
    • Week One Done
      vivetool earned a badge
      Week One Done
    • Reacting Well
      pnajbar earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      701
    2. 2
      ATLien_0
      280
    3. 3
      Michael Scrip
      209
    4. 4
      +FloatingFatMan
      196
    5. 5
      Steven P.
      130
  • Tell a friend

    Love Neowin? Tell a friend!