How can I programatically tell Windows taskbar to open (or close) a given toolbar?

元气小坏坏 提交于 2019-11-30 18:58:00

问题


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.


回答1:


  • 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.




回答2:


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




回答3:


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.




回答4:


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.




回答5:


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.




回答6:


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...



来源:https://stackoverflow.com/questions/347274/how-can-i-programatically-tell-windows-taskbar-to-open-or-close-a-given-toolba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!