如何以编程方式告诉 Windows 任务栏打开(或关闭)给定的工具栏?

发布于 2024-07-09 13:58:59 字数 259 浏览 5 评论 0原文

我编写了一个在任务栏上运行的工具栏。 不幸的是,安装后,用户必须手动启用它。 有没有办法告诉资源管理器打开(或关闭)给定的工具栏?

我希望安装程序 NSIS 在安装完成后打开工具栏(我意识到需要一个插件)。

我还想知道是否可以自动为所有用户启用工具栏,例如在多个用户共享一台 PC 的企业环境中。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

漫雪独思 2024-07-16 13:59:00
  • 此 CodeProject 注释通过模拟按键来实现
  • Vista+ 有 API 可以做到这一点,使用 ShowDeskBandHideDeskBand
  • 编辑:此代码现在可以添加桌带对象(来自 Pinvoke.net,以及 这些 两个 MSDN 论坛问题):

    <前><代码>[ComImport]
    [接口类型(ComInterfaceType.InterfaceIsIUnknown)]
    [指南(“4CF504B0-DE96-11D0-8B3F-00A0C911E8E5”)]
    公共接口 IBandSite
    {
    [保留签名]
    uint AddBand([In, MarshalAs(UnmanagedType.IUnknown)] 对象 pUnkSite);
    [保留签名]
    无效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}");
    类型 TrayBandSiteService = Type.GetTypeFromCLSID(ITrayBand, true);
    IBandSite BandSite = Activator.CreateInstance(TrayBandSiteService) as IBandSite;
    对象 DeskbandObject = CoCreateInstance(Deskband, null, CLSCTX.CLSCTX_INPROC_SERVER, IUnknown);
    返回 BandSite.AddBand(DeskbandObject);
    }

并且,一个示例使用:

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

对RemoveBand 的类似调用也可以实现这一点,但是到目前为止,我还无法让该代码工作。 另一个问题:添加的桌面带会在添加它的应用程序关闭时关闭。

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

夏尔 2024-07-16 13:59:00

您可能需要查看这篇文章。 看起来你只能在 Vista 中使用 ITrayDeskBand接口

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

流心雨 2024-07-16 13:59:00

我现在找不到确切的网址,但我记得 PDC2008 周围对此进行了一些讨论,基本上没有专门启用此功能,因此随机程序无法在未经用户同意的情况下填充任务栏。

这样做的一个副作用是,很少有用户甚至默认启用 WMP 桌面栏。

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.

蝶…霜飞 2024-07-16 13:59:00

据我了解,任务栏位置和值等存储在注册表中(忘记了确切位置),因此如果您找到特定的注册表项,您可以获取其位置并让安装程序在计算机上插入注册表项,以便启用任务栏。

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.

故人的歌 2024-07-16 13:59:00

这并不是您问题的真正答案,但请注意:不要在 .NET 中编写 shell 扩展(任务栏是 shell 扩展)!

原因如下

基本上,您正在破坏其他应用程序。

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.

各空 2024-07-16 13:59:00

如果你检查得好,谷歌工具带存在,而一个exe在后面运行(GoogleDesktop.exe),所以如果你坚持谷歌或搜索栏的实例化方式,你应该再次检查TrayBandSiteService并制作一个支持exe...

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文