Solved

Removing Another Applications System Tray Icon

Posted on 2008-10-13
5
531 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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…

932 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now