<p>This problem has been afflicting me for quite a while and it's been really annoying.</p>

<p>Every time I login after a reboot/power cycle the explorer takes some time to show up.
I've taken the step of waiting for all the services to boot up and then I login, but it doesn't make any difference.
The result is always the same: Some of the icons do not show up even if the applications have started.</p>

<p>I've dug a bit on the code that makes one application "stick" an icon in there, but is there an API call that one can perform so explorer re-reads all that icon info? Like invalidate or redraw or something of the sort?</p>

<hr>

<p>Apparently, it looks like Jon was right and it's not possible to do it.</p>

<p>I've followed Bob Dizzle and Mark Ransom code and build this (Delphi Code):</p>

<pre><code>procedure Refresh;
var
  hSysTray: THandle;
begin
  hSysTray := GetSystrayHandle;
  SendMessage(hSysTray, WM_PAINT, 0, 0);
end;

function GetSystrayHandle: THandle;
var
  hTray, hNotify, hSysPager: THandle;
begin
  hTray := FindWindow('Shell_TrayWnd', '');
  if hTray = 0 then
  begin
    Result := hTray;
    exit;
  end;

  hNotify := FindWindowEx(hTray, 0, 'TrayNotifyWnd', '');
  if hNotify = 0 then
  begin
    Result := hNotify;
    exit;
  end;

  hSyspager := FindWindowEx(hNotify, 0, 'SysPager', '');
  if hSyspager = 0 then
  begin
    Result := hSyspager;
    exit;
  end;

  Result := FindWindowEx(hSysPager, 0, 'ToolbarWindow32', 'Notification Area');
end;</code></pre>

<p>But to no avail.</p>

<p>I've even tried with <pre><code>InvalidateRect()</code></pre> and still no show.</p>

<p>Any other suggestions?</p>

[{'answer_id': 74769, 'author': 'Jonathan Sayce', 'author_id': 13153, 'author_profile': 'https://Stackoverflow.com/users/13153', 'pm_score': 2, 'selected': False, 'text': "<p>As far as I know that isn't possible Gustavo - it's up to each application to put its notifyicon in the systray, and ensure it's kept in the right state. </p>\n\n<p>You'll notice sometimes when explorer.exe crashes that certain icons don't reappear - this isn't because their process has crashed, simply that their application hasn't put the notifyicon in the systray when the new instance of explorer.exe started up. Once again, it's the application that's responsible.</p>\n\n<p>Sorry not to have better news for you!</p>\n"}, {'answer_id': 74781, 'author': 'Bob Dizzle', 'author_id': 9581, 'author_profile': 'https://Stackoverflow.com/users/9581', 'pm_score': 2, 'selected': False, 'text': '<p>Include following code with yours to refresh System Tray.</p>\n\n<pre><code>public const int WM_PAINT = 0xF;\n[DllImport("USER32.DLL")]\npublic static extern int SendMessage(IntPtr hwnd, int msg, int character,\n                                     IntPtr lpsText);\n\nSend WM_PAINT Message to paint System Tray which will refresh it.\nSendMessage(traynotifywnd, WM_PAINT, 0, IntPtr.Zero);\n</code></pre>\n'}, {'answer_id': 74871, 'author': 'Mark Ransom', 'author_id': 5987, 'author_profile': 'https://Stackoverflow.com/users/5987', 'pm_score': 1, 'selected': False, 'text': '<p>I use the following C++ code to get the window handle to the tray window.  <strong>Note:</strong> this has only been tested on Windows XP.</p>\n\n<p><pre><code>HWND FindSystemTrayIcons(void)\n{\n    // the system tray icons are contained in a specific window hierarchy;\n    // use the Spy++ utility to see the chain\n    HWND hwndTray = ::FindWindow("Shell_TrayWnd", "");\n    if (hwndTray == NULL)\n        return NULL;\n    HWND hwndNotifyWnd = ::FindWindowEx(hwndTray, NULL, "TrayNotifyWnd", "");\n    if (hwndNotifyWnd == NULL)\n        return NULL;\n    HWND hwndSysPager = ::FindWindowEx(hwndNotifyWnd, NULL, "SysPager", "");\n    if (hwndSysPager == NULL)\n        return NULL;\n    return ::FindWindowEx(hwndSysPager, NULL, "ToolbarWindow32", "Notification Area");\n}\n</pre></code></p>\n'}, {'answer_id': 1052920, 'author': 'Louis Davis', 'author_id': 103205, 'author_profile': 'https://Stackoverflow.com/users/103205', 'pm_score': 5, 'selected': True, 'text': '<p>Take a look at this blog entry: <a href="http://malwareanalysis.com/CommunityServer/blogs/geffner/archive/2008/02/15/985.aspx" rel="noreferrer">REFRESHING THE TASKBAR NOTIFICATION AREA</a>. I am using this code to refresh the system tray to get rid of orphaned icons and it works perfectly.\nThe blog entry is very informative and gives a great explanation of the steps the author performed to discover his solution.</p>\n\n<pre><code>#define FW(x,y) FindWindowEx(x, NULL, y, L"")\n\nvoid RefreshTaskbarNotificationArea()\n{\n    HWND hNotificationArea;\n    RECT r;\n\n    GetClientRect(\n        hNotificationArea = FindWindowEx(\n            FW(FW(FW(NULL, L"Shell_TrayWnd"), L"TrayNotifyWnd"), L"SysPager"),\n            NULL,\n            L"ToolbarWindow32",\n            // L"Notification Area"), // Windows XP\n            L"User Promoted Notification Area"), // Windows 7 and up\n        &amp;r);\n\n    for (LONG x = 0; x &lt; r.right; x += 5)\n        for (LONG y = 0; y &lt; r.bottom; y += 5)\n            SendMessage(\n                hNotificationArea,\n                WM_MOUSEMOVE,\n                0,\n                (y &lt;&lt; 16) + x);\n}\n</code></pre>\n'}, {'answer_id': 1052937, 'author': 'bugmagnet', 'author_id': 426, 'author_profile': 'https://Stackoverflow.com/users/426', 'pm_score': 2, 'selected': False, 'text': '<p>I covered this issue last year on my <a href="http://codeaholic.blogspot.com" rel="nofollow noreferrer">Codeaholic</a> weblog in an article entitled <a href="http://codeaholic.blogspot.com/2008/07/delphi-updating-systray.html" rel="nofollow noreferrer">[Delphi] Updating SysTray</a>. </p>\n\n<p>My solution is a Delphi ActiveX/COM DLL. The download link still works (though for how much longer I don\'t know as my <a href="http://www.plug.org.au" rel="nofollow noreferrer">PLUG</a> membership has lapsed.)</p>\n'}, {'answer_id': 18038441, 'author': 'Stephen Klancher', 'author_id': 221018, 'author_profile': 'https://Stackoverflow.com/users/221018', 'pm_score': 4, 'selected': False, 'text': '<p>Two important details for anyone using Louis\'s answer (from <a href="http://malwareanalysis.com/CommunityServer/blogs/geffner/archive/2008/02/15/985.aspx">REFRESHING THE TASKBAR NOTIFICATION AREA</a>) on Windows 7 or Windows 8:</p>\n\n<p>First, as the answer was reflected to show, the window titled "Notification Area" in XP is now titled "User Promoted Notification Area" in Windows 7 (actually probably Vista) and up.</p>\n\n<p>Second, this code does not clear icons that are currently hidden.  These are contained in a separate window.  Use the original code to refresh visible icons, and the following to refresh hidden icons.</p>\n\n<pre><code>//Hidden icons\nGetClientRect(\n    hNotificationArea = FindWindowEx(\n        FW(NULL, L"NotifyIconOverflowWindow"),\n        NULL,\n        L"ToolbarWindow32",\n        L"Overflow Notification Area"),\n    &amp;r);\n\nfor (LONG x = 0; x &lt; r.right; x += 5)\n    for (LONG y = 0; y &lt; r.bottom; y += 5)\n        SendMessage(\n            hNotificationArea,\n            WM_MOUSEMOVE,\n            0,\n            (y &lt;&lt; 16) + x);\n</code></pre>\n\n<p>For anyone who just needs a utility to run to accomplish this, rather than code, I built a simple exe with this update: <a href="http://projects.stephenklancher.com/project/id/88/Refresh_Notification_Area">Refresh Notification Area</a></p>\n'}, {'answer_id': 53938471, 'author': 'user2712225', 'author_id': 2712225, 'author_profile': 'https://Stackoverflow.com/users/2712225', 'pm_score': 0, 'selected': False, 'text': '<p>@Skip R, and anyone else wanting to do this in C, with this code verified compiled in a recent (most recent) mingw on Windows 10 64 bit (but with the mingw 32 bit package installed), this seems to work in Windows XP / 2003 to get rid of stale notification area icons.</p>\n\n<p>I installed mingw via Chocolatey, like this:</p>\n\n<pre><code>choco install mingw --x86 --force --params "/exception:sjlj"\n</code></pre>\n\n<p>(your mileage may vary on that, on my system, the compiler was then installed here:</p>\n\n<pre><code>C:\\ProgramData\\chocolatey\\lib\\mingw\\tools\\install\\mingw32\\bin\\gcc.exe\n</code></pre>\n\n<p>and then a simple</p>\n\n<pre><code>gcc refresh_notification_area.c\n</code></pre>\n\n<p>yielded an a.exe which solved a stale notification area icon problem I was having on Windows 2003 (32 bit).</p>\n\n<p>The code, adapted from @Stephen Klancher above is (note this may only work on Windows XP/2003, which fulfilled my purposes):</p>\n\n<pre><code>#include &lt;windows.h&gt;\n\n#define FW(x,y) FindWindowEx(x, NULL, y, "")\n\nint main ()\n{\n\n    HWND hNotificationArea;\n    RECT r;\n\n    //WinXP\n    // technique found at:\n    // https://stackoverflow.com/questions/74723/can-you-send-a-signal-to-windows-explorer-to-make-it-refresh-the-systray-icons#18038441\n    GetClientRect(\n        hNotificationArea = FindWindowEx(\n            FW(FW(FW(NULL, "Shell_TrayWnd"), "TrayNotifyWnd"), "SysPager"),\n            NULL,\n            "ToolbarWindow32",\n            "Notification Area"),\n        &amp;r);\n\n    for (LONG x = 0; x &lt; r.right; x += 5)\n        for (LONG y = 0; y &lt; r.bottom; y += 5)\n            SendMessage(\n                hNotificationArea,\n                WM_MOUSEMOVE,\n                0,\n                (y &lt;&lt; 16) + x);\n\n  return 0;\n\n}\n</code></pre>\n'}, {'answer_id': 56088800, 'author': 'Yuanhui', 'author_id': 5001634, 'author_profile': 'https://Stackoverflow.com/users/5001634', 'pm_score': 1, 'selected': False, 'text': '<p>After lots of times trying I found that there are three issues you must to know:</p>\n\n<ul>\n<li>The parent of hidden tray window is <code>NotifyIconOverflowWindow</code>, other than <code>Shell_TrayWnd</code>.</li>\n<li>You shouldn\'t use <code>caption</code> parameter of <code>FindWindowEx</code> to find a window, because these is lots of langue versions of Windows OS, they are not always be the same title Obviously.</li>\n<li>Use <code>spy++</code> of Visual Studio to find or make assurance what you want.</li>\n</ul>\n\n<p>So, I changed code from @Stephen Klancher and @Louis Davis, thank you guys.</p>\n\n<p>The following code worked for me.</p>\n\n<pre><code>#define FW(x,y) FindWindowEx(x, NULL, y, L"")\nvoid RefreshTaskbarNotificationArea()\n{\n    HWND hNotificationArea;\n    RECT r;\n    GetClientRect(hNotificationArea = FindWindowEx(FW(NULL, L"NotifyIconOverflowWindow"), NULL, L"ToolbarWindow32", NULL), &amp;r);\n    for (LONG x = 0; x &lt; r.right; x += 5)\n    {\n        for (LONG y = 0; y &lt; r.bottom; y += 5)\n        {\n            SendMessage(hNotificationArea, WM_MOUSEMOVE, 0, (y &lt;&lt; 16) + x);\n        }\n    }\n}\n</code></pre>\n'}, {'answer_id': 73008007, 'author': 'tom42', 'author_id': 10959519, 'author_profile': 'https://Stackoverflow.com/users/10959519', 'pm_score': 0, 'selected': False, 'text': '<p>Powershell solution, put this in your script</p>\n<pre><code>Add-Type -AssemblyName System.Windows.Forms\nAdd-Type @&quot;\nusing System;\nusing System.Runtime.InteropServices;\n\npublic struct RECT {\n  public int left;\n  public int top;\n  public int right;\n  public int bottom;\n}\n\npublic class pInvoke {\n  [DllImport(&quot;user32.dll&quot;)]\n  public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);\n\n  [DllImport(&quot;user32.dll&quot;)]\n  public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);\n\n  [DllImport(&quot;user32.dll&quot;)]\n  public static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);\n\n  [DllImport(&quot;user32.dll&quot;)]\n  public static extern IntPtr SendMessage(IntPtr hWnd, uint msg, int wParam, int lParam);\n  \n  public static void RefreshTrayArea() {\n    IntPtr systemTrayContainerHandle = FindWindow(&quot;Shell_TrayWnd&quot;, null);\n    IntPtr systemTrayHandle = FindWindowEx(systemTrayContainerHandle, IntPtr.Zero, &quot;TrayNotifyWnd&quot;, null);\n    IntPtr sysPagerHandle = FindWindowEx(systemTrayHandle, IntPtr.Zero, &quot;SysPager&quot;, null);\n    IntPtr notificationAreaHandle = FindWindowEx(sysPagerHandle, IntPtr.Zero, &quot;ToolbarWindow32&quot;, &quot;Notification Area&quot;);\n    if (notificationAreaHandle == IntPtr.Zero) {\n      notificationAreaHandle = FindWindowEx(sysPagerHandle, IntPtr.Zero, &quot;ToolbarWindow32&quot;, &quot;User Promoted Notification Area&quot;);\n      IntPtr notifyIconOverflowWindowHandle = FindWindow(&quot;NotifyIconOverflowWindow&quot;, null);\n      IntPtr overflowNotificationAreaHandle = FindWindowEx(notifyIconOverflowWindowHandle, IntPtr.Zero, &quot;ToolbarWindow32&quot;, &quot;Overflow Notification Area&quot;);\n      RefreshTrayArea(overflowNotificationAreaHandle);\n    }\n    RefreshTrayArea(notificationAreaHandle);\n  }\n\n  private static void RefreshTrayArea(IntPtr windowHandle) {\n    const uint wmMousemove = 0x0200;\n    RECT rect;\n    GetClientRect(windowHandle, out rect);\n    for (var x = 0; x &lt; rect.right; x += 5)\n      for (var y = 0; y &lt; rect.bottom; y += 5)\n        SendMessage(windowHandle, wmMousemove, 0, (y &lt;&lt; 16) + x);\n  }\n}\n&quot;@\n</code></pre>\n<p>Then use <code>[pInvoke]::RefreshTrayArea()</code> to reset</p>\n'}]
['https://Stackoverflow.com/questions/74723', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/8167/']