4

I have an app that sometimes dynamically adds and removes entries from the start menu (and the Desktop), by placing shortcuts (created with WshShellClass) in the start menu folder (Environment.SpecialFolder.StartMenu). If any such changes occur, I already notify the shell of changes using SHChangeNotify, as described here. Specifically:

    private static void _RefreshWindowsDesktop()
    {
        // http://stackoverflow.com/a/647286/1600

        NativeMethods.SHChangeNotify(NativeMethods.HChangeNotifyEventID.SHCNE_ASSOCCHANGED,
                                     NativeMethods.HChangeNotifyFlags.SHCNF_FLUSH,
                                     IntPtr.Zero, IntPtr.Zero);
    }

However, on Windows 10, Start Menu search frequently breaks (I've never seen this behavior in Windows Vista or 7), where a new shortcut often doesn't show up for days, and in turn, an old shortcut that has been deleted days ago still shows up as a "search result". This is presumably due to changes to make modern apps appear in the Start Menu alongside classic desktop apps, but I'm not sure; online guides to that effect frankly strike me as voodoo.

Worse, when invoking that shortcut, Windows 10 just does nothing — there's no error indicating that the shortcut points nowhere (because it doesn't exist), nor does Windows learn and remove it afterwards.

So, my hope is there's a method akin SHChangeNotify to explicitly tell Windows 10 to invalidate or rebuild its Start Menu cache, such as asking it to reindex that particular folder, or telling it to manually add/remove an item from the index.

My app is WPF, but if a native method exists, I can detect the OS version and then conditionally invoke it. (Or even write an external Windows 10-specific UWP background app to launch if needed.)

Sören Kuklau
  • 19,454
  • 7
  • 52
  • 86
  • There are user specific start menu/desktop and common for all users. Do you handle this correctly? E.g. what if you trying to delete item from local user menu item, while it's in common? – Sinatr Jun 27 '18 at 09:32
  • These short cuts are all user-specific and placed in the user profile's Start Menu directory, so that shouldn't be a problem. – Sören Kuklau Jun 27 '18 at 17:13

0 Answers0