We help IT Professionals succeed at work.

Removing Another Applications System Tray Icon

582 Views
Last Modified: 2013-12-03
I've dug around and can't seem to find this...

I want to be able to remove an icon in the system tray belonging to another application programmatically in C++.  

I've done similar things in the past with normal windows, but the system tray is it's own beast, and I'm sure someone has done it before (not to mention lots of utilities to perform this manually are out there).

Any help appreciated.
Comment
Watch Question

Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Commented:
it's quite possible that the program which put the icon there would notice it had gone and put it back.

get this link
https://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_20106981.html?sfQueryTermInfo=1+hide+icon+trai

Author

Commented:
It's actually a commercial ActiveX control that puts it there on CoCreation / instantiation.  Possibly one of the most annoying ActiveX control behaviours.  

It makes sense if you don't want to have your own tray icon, but since I need my own tray icon, two for the same application isn't really viable.

I'll be checking out the 1st option you put forward later today, will let you know.  I'd been all over codeproject and that gem has slipped me by.

Author

Commented:
I was sent on a bit of a journey, but the above sent me in the right direction.  You are a star.

The code on codeproject isn't 100% correct, as there are a few more steps I thought I'd include here.

I'll work backwards, and then summarise it.

The CProcessData is worth using, but if it doesn't work out of the box, you are going to have to modify it to debug.  Generally, from my experience, and what I read on the net, you need to set priveleges.  There are methods to do this in the links above.

Using the functions above, the privilege to set is "SeDebugPrivilege", and can be done by calling:
SetPrivilege((HANDLE)dwTrayPid, SE_DEBUG_NAME, true);

Now in this function it does a call to "AdjustTokenPrivileges".  

If you debug and find that "AdjustTokenPrivileges" is returning false... you need to do this early in your application start up.

      if (!OpenThreadToken(GetCurrentThread(), TOKEN_ADJUST_PRIVILEGES, FALSE, &hMyToken))
      {
            ImpersonateSelf(SecurityImpersonation);
            OpenThreadToken(GetCurrentThread(), TOKEN_ADJUST_PRIVILEGES, FALSE, &hMyToken)
      }

Now the above code isn't final, you should check the success or failure, and put in any error handling... so waht does this all mean?

To allocate memory with VirtualAllocEx, you need permission.  To set the permission you need to obtain the thread token to adjust token privileges.  If you can't obtain the thread token because one doesn't exist, you need to call ImpersonateSelf, and try again.

Now if after that you still can't get it to work, I have no idea.  I do know you can set up privileges via the manifest (probably a cleaner, better way) but in the end I couldn't find out how to do it, just that it was possible.

Thanks for the advice above, it was invaluable, and the core of the solution.  What I have put in this post were issues I ran into trying to execute the soluiton.

Author

Commented:
I put a post on the question.  You sent me in the right direction.  Superstar.  Thanks.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.