0

I'm having a heck of a time trying to refresh the desktop using a winforms VB.Net application I have written.

The application modifies the registry to un-hide files and folders / protected Operating System files. I have a working method to refresh all Windows Explorer windows after the change to the registry, but the desktop is still left unchanged unless I manually refresh it.

Clicking on the desktop and refreshing using the F5 key on the keyboard successfully refreshes the desktop so that the user can view the hidden icons. But when I use the code below, the desktop flickers, but the hidden files are not displayed unless I physically click on the desktop with the mouse and press F5 on the keyboard:

Private Declare Function SHChangeNotify Lib "Shell32.dll" (ByVal wEventID As Int32, _
                                                               ByVal uFlags As Int32, _
                                                               ByVal dwitem1 As Int32, _
                                                               ByVal deitem2 As Int32) As Int32

Private Sub refreshDesktop()

SHChangeNotify(&H8000000, &H1000, 0, 0)

End Sub

I can't imagine that it should be this difficult. Another alternative I have considered is using SendKeys.Send("{F5}") but am having trouble bringing focus to the desktop to apply this method to the desktop and not the form. I am testing this on a Windows 7 machine.

Any ideas how to accomplish this / any suggestions or code they know will work is greatly appreaciated as always.


UPDATE: I have put together the SHChangeNotify method signature from Pinvoke.net in-place of what I have above, but it is still returning the same results of the desktop icons flash like the desktop actually IS being refreshed, but not to the point of showing hidden icons, like F5 on the keyboard does. See below for edited code after referenceing Pinvoke.net

<DllImport("Shell32.dll")> _
    Shared Sub SHChangeNotify(ByVal wEventID As Int32, _
                              ByVal uFlags As Int32, _
                              ByVal dwitem1 As Int32, _
                              ByVal deitem2 As Int32)
    End Sub


 Private Sub refreshDesktop()

        SHChangeNotify(&H8000000, &H1000, 0, 0)

 End Sub
ganjeii
  • 1,168
  • 1
  • 15
  • 26
  • The method signature doesnt match that on [PInvoke.Net](http://pinvoke.net/default.aspx/shell32/SHChangeNotify.html) – Ňɏssa Pøngjǣrdenlarp Aug 28 '15 at 18:21
  • Hey Plutonix thanks for the info. It looks like the examples are for updating file extensions. Might you have some insight as to a working example to update hidden files? The format at [Pinvoke.net](http://pinvoke.net/default.aspx/shell32/SHChangeNotify.html) is not something I am familiar with. Though I may just not be understanding, I am still pretty junior. – ganjeii Aug 28 '15 at 18:33
  • @ganjeii please see your other post that has this same problem. I have a solution for you. There is no need to post another question like this when you already did. http://stackoverflow.com/questions/32234984/replicate-windows-unhide-folders-and-files-function – Trevor Aug 29 '15 at 13:28
  • @436f6465786572 Yea my bad I figured, this was kind of a sub-question to my original question in my other thread. Should I just delete this one? – ganjeii Aug 29 '15 at 14:05

0 Answers0