Possible Duplicate:
remove application icon from the taskbar using .net with c#
I am adding window application form icon to taskbar using this code
ResourceManager resManager = new ResourceManager("SMSLAgent.Properties.Resources", GetType().Module.Assembly);
notifyicon.Icon = (Icon)resManager.GetObject("SMSLAgent");
notifyicon.Visible = true;
notifyicon.Text = "PA Agent";
this.Hide();
this.ShowInTaskbar = false;
this.SetVisibleCore(false);
This code is added in asp.net windows form application initilizaion method. It works but the problem is, I am running windows form exe using windows service with administrator privilege in windows7.
On windows reboot not adding icon showing as a windows form application but when I restart my windows service it works fine.
What’s wrong here?
This apparently has something to do with being (not) logged in. This could be checked by enabling autologin and making sure you show the icon after it kicks in. Same thing might happen with logging in via RDP and hitting a different session. We had some software showing an icon like this and had to use “mstsc /console”. Given that allowing services to interact with desktop (even if in somewhat indirect way) is frowned upon anyway and the winform app will have kind of its own desktop under Windows Server XXX (do not remember which, but it differs from what you’ll see in XP; try showing a window and see), we went with an application startable as either completely non-interactive service or winforms with icon (the later either manual or scheduled).
Still not a complete answer, but I hope it will help get one.