I use the following code in the FormCreate event handler to create a system tray icon. When I run my program the system tray icon appears fine.
I set my application be
The problem was caused because the current directory during start up is not the directory in which the executable lives.
So getCurrentDir was actually returning different directories at startup and when the app was run at any other time.
My application was making the poor assumption that the current dir would be the one in which the executable resides.
This assumption was causing the app to never reach the tray icon adding code at all. Once I fixed up the directory issue the code ran and correctly created the icon.
You're attempting to create the icon before Explorer has fully started. You should handle errors gracefully (scroll down to "Handling Shell_NotifyIcon failure").
You should also handle the TaskbarCreated notification -- it enables you to recreate your icons after Explorer crashes and restarts.