views:

1143

answers:

6

I have written a toolbar that runs on the taskbar. Unfortunately, after it is installed, the user has to enable it manually. Is there a way to tell explorer to open (or close) a given toolbar?

I would like for the installer, NSIS, to turn on the toolbar when the installation is complete (I realize that a plugin would be necessary).

I also want to know if it's possible to automatically enable a toolbar for all users, for example in a corporate environment where multiple users would share a PC.

+2  A: 

I can't find the exact url right now, but I remember there being some discussion of this around PDC2008 where basically this was not enabled specifically so that random programs couldn't populate the taskbar w/o the users consent.

A side effect of this is that very few users even enable the WMP deskbar by default.

Ben Childs
I think that there must be a way to do this, because I've seen several Microsoft installers (like Search) and Google automatically turn on their toolbars.
Chris Thompson
Hmm, it is always possible that there is some way to do this that would of course be unsupported and not guaranteed to work in future versions.
Ben Childs
+3  A: 

You might want to check out this article. It looks like you can only do this ("officially" anyway) in Vista using the ITrayDeskBand interface.

spmason
+9  A: 
  • This CodeProject comment does it by simulating key presses
  • Vista+ has API to do this, with ShowDeskBand and HideDeskBand
  • Edit: This code can now Add a deskband object (from Pinvoke.net, and these two MSDN forum questions):

    [ComImport]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    [Guid("4CF504B0-DE96-11D0-8B3F-00A0C911E8E5")]
    public interface IBandSite
    {
        [PreserveSig]
        uint AddBand([In, MarshalAs(UnmanagedType.IUnknown)] Object pUnkSite);
        [PreserveSig]
        void RemoveBand(uint dwBandID);
    }
    
    
    private uint AddDeskbandToTray(Guid Deskband)
    {
        Guid IUnknown = new Guid("{00000000-0000-0000-C000-000000000046}");
        Guid ITrayBand = new Guid("{F60AD0A0-E5E1-45cb-B51A-E15B9F8B2934}");   
        Type TrayBandSiteService = Type.GetTypeFromCLSID(ITrayBand, true);
        IBandSite BandSite = Activator.CreateInstance(TrayBandSiteService) as IBandSite;
        object DeskbandObject = CoCreateInstance(Deskband, null, CLSCTX.CLSCTX_INPROC_SERVER, IUnknown);
        return BandSite.AddBand(DeskbandObject);
    }
    

And, an example use:

Guid address_toolbar_guid = new Guid("{01E04581-4EEE-11D0-BFE9-00AA005B4383}");
uint band_id = AddDeskbandToTray(address_toolbar_guid);

It would make sense that a similar call to RemoveBand would also do the trick, but as of yet, I can't get that code to work. Another issue: the added deskband closes when the application that added it closes.

Factor Mystic
What about the IBandSite interface? I haven't found any examples of how to use the SetBandState method, but it looks like it has potential.
Chris Thompson
IBandSite did work, at least for adding a deskband. Code updated.
Factor Mystic
Very thorough answer. +1
Andrew
The toolbar IS the application, so it doesn't work if the toolbar disappears when application to open the toolbar closes. I'm more looking for something like the Microsoft Search installer or Google Desktop installer that permanently turns on the toolbar.
Chris Thompson
Just for the record, this code doesn't do what I need. The AddBand method doesn't cause a toolbar to stay loaded once the calling application has closed.
Chris Thompson
This works great on my system, but on some end-users system of my application `CreateInstance` throws a COMException with error code 80040154. Any idea what might cause that?
Daniel Stutzbach
+1  A: 

From what I understand, taskbars locations and values etc are stored in the registry (forgot exact location) so if you find the specific registry key you could take its location and make your installer insert the registry key on the computer so the taskbar is enabled.

Mike Stanford
+1  A: 

Not really an answer to your question, but please, please: do not write shell extensions (and a taskbar is a shell extension) in .NET!

Here's why.

Basically, you're breaking other apps.

Stefan
I actually am familiar with the reasons why not to do it (at least I do now, I didn't when I started). I'm a self-taught programmer and I have no experience with C/C++. I started with classes in VB.NET and have taught myself C#.
Chris Thompson
A: 

if you check well, google toolband exists while an exe is running behind (GoogleDesktop.exe) so if you insist on the way google or search bar are instantiated you should check again TrayBandSiteService and make a support exe...

Enrique