Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh the windows desktop programmatically (i.e. F5) from C#?

Tags:

c#

.net

Yeah, I know this seems like a dumb question, its just a one-off hack I need to wrap up a somewhat mundane task so I can move on to something more interesting.

EDIT: Maybe more info would help: I'm trying to remove some shortcuts from the desktop and I need the user to see it removed right away (so they don't have to press F5).

like image 521
DSO Avatar asked Mar 15 '09 04:03

DSO


2 Answers

You can use the SHChangeNotify API.

[System.Runtime.InteropServices.DllImport("Shell32.dll")]
private static extern int SHChangeNotify(int eventId, int flags, IntPtr item1, IntPtr item2);

and then call it this way

SHChangeNotify(0x8000000, 0x1000, IntPtr.Zero, IntPtr.Zero);
like image 173
Tom Anderson Avatar answered Oct 21 '22 18:10

Tom Anderson


I think you're looking for IActiveDesktop::ApplyChanges. You will need to access this via the COM interface, which should be fairly easy with all the documentation Microsoft provides on COM Interop.

like image 45
John T Avatar answered Oct 21 '22 18:10

John T