• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 553
  • Last Modified:

Removing Another Applications System Tray Icon

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.
0
vaughanknight
Asked:
vaughanknight
  • 3
  • 2
1 Solution
 
mannujamCommented:
0
 
mannujamCommented:
it's quite possible that the program which put the icon there would notice it had gone and put it back.

get this link
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_20106981.html?sfQueryTermInfo=1+hide+icon+trai
0
 
vaughanknightAuthor 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.
0
 
vaughanknightAuthor 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.
0
 
vaughanknightAuthor Commented:
I put a post on the question.  You sent me in the right direction.  Superstar.  Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now