How to "Update" Vista's Launch Menu Programmatically

I am working on a code snippet that deletes the extra folder that we have in the user launch menu. I start by deleting all the shortcuts that it contains, and then delete the folder.

After that, I can confirm that the shortcuts have been removed from the Start menu, but their containing folder remains in the list in the Start menu. So, I checked the file system for such a folder and did not find it. Suspecting that this was some kind of update problem, I registered the user and returned to Vista and found that the folder was now removed from the Start menu list.

How annoying ... Does anyone know how to programmatically make Vista update the Start menu so that the user does not see this empty folder before logging out?

Thanks, Ben

+3
source share
2 answers

I tried to implement this myself, but it did not work properly using SendMessageTimeout.

Instead, it worked when I used SHGetSpecialFolderLocation (CSIDL_STARTMENU) SHChangeNotify (SHCNE_UPDATEDIR, SHCNF_IDLIST, pidl, NULL);

See this article for sample C ++ code: http://support.microsoft.com/kb/q193293/

Tested on Windows Server 2008 Enterprise (x86) with Service Pack 1 (SP1).

+2
source

This article has the answer you are looking for:

http://social.msdn.microsoft.com/forums/en-US/winforms/thread/ce540c7d-a113-4f39-956e-0af6bc91abd3/

Answer:

class Program
 {
  [DllImport("user32.dll", SetLastError = true)]
  private static extern IntPtr SendMessageTimeout ( IntPtr hWnd, int Msg, IntPtr wParam, string lParam, uint fuFlags, uint uTimeout, IntPtr lpdwResult );

  private static readonly IntPtr HWND_BROADCAST = new IntPtr(0xffff);
  private const int WM_SETTINGCHANGE = 0x1a;
  private const int SMTO_ABORTIFHUNG = 0x0002;

  static void Main ( string[] args )
  {
   SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, IntPtr.Zero, null, SMTO_ABORTIFHUNG, 100, IntPtr.Zero);
  }
 }
+2
source

Source: https://habr.com/ru/post/1734283/


All Articles