Solved

Removing Another Applications System Tray Icon

Posted on 2008-10-13
5
545 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.
0
Comment
Question by:vaughanknight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
mannujam earned 500 total points
ID: 22713663
0
 
LVL 2

Expert Comment

by:mannujam
ID: 22714065
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
 

Author Comment

by:vaughanknight
ID: 22717124
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
 

Author Comment

by:vaughanknight
ID: 22721974
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
 

Author Closing Comment

by:vaughanknight
ID: 31407105
I put a post on the question.  You sent me in the right direction.  Superstar.  Thanks.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question