【问题标题】:Sending toast notification from Windows service throws HRESULT: 0x80070005 (E_ACCESSDENIED)从 Windows 服务发送 toast 通知会引发 HRESULT: 0x80070005 (E_ACCESSDENIED)
【发布时间】:2021-11-04 16:15:02
【问题描述】:

引发错误的代码行是:

new ToastContentBuilder()
    .AddText("Title of notification")
    .AddText("Body of notification")
    .Show();

该程序是用 C# 制作的 Windows 服务,使用 Wix 安装程序安装。 ToastContentBuilder 来自 Microsoft.Toolkit.Uwp.Notifications 命名空间。在Product.wxs 中,我已将 ServiceInstall 标签设置为:

<SeviceInstall Id="ServiceInstaller"
               Type="ownProcess"
               Vital="yes"
               Name="MyProcessName"
               DisplayName="My Process Name"
               Description="My process description."
               Start="auto"
               Account="LocalSystem"
               ErrorControl="normal"
               Arguments=""
               Interactive="yes" />

在 Windows 的服务查看器中,我检查了进程的属性,它以本地系统帐户登录,并选中了“允许服务与桌面交互”框。

我知道similar question,但这个问题没有答案,而且似乎不是使用 Wix 安装的服务,所以它用处不大。

我会很感激任何线索。我对 Wix 不是很熟悉,所以 Product.wxs 中的某些内容可能有问题。

【问题讨论】:

  • 我回答了我能回答的部分。我不知道系统可以向用户发送敬酒。对于一个,哪个会话?对于两个,权限。我想最简单的测试方法是创建一个简单的 console.exe,它可以发送一个 toast,然后尝试使用 PSEXEC 作为 SYSTEM 运行它。

标签: c# .net windows service wix


【解决方案1】:

我从未尝试从 Windows 服务发送 toast 消息。我已经从托盘应用程序和以用户身份运行的计划任务发送了 toast 消息。

要在 toast 中添加点击事件,您必须在开始菜单中创建一个带有快捷方式的应用,如下所示:

<Shortcut Id="sc1" Name="Some App" Directory="ProgramMenuFolder" Description="Some App">
  <!--AUMID-->
  <ShortcutProperty Key="System.AppUserModel.ID" Value="WindowsNotifications.SomeApp" />
  <!--COM CLSID, specifying which CLSID to activate when toast clicked-->
  <ShortcutProperty Key="System.AppUserModel.ToastActivatorCLSID" Value="guid-used-in-code" />
</Shortcut>

在你的代码中你必须实现

[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces(typeof(INotificationActivationCallback))]
[Guid("guid-used-in-code"), ComVisible(true)]

    protected override void OnStartup(StartupEventArgs e)
    {
        // Register AUMID, COM server, and activator
        DesktopNotificationManagerCompat.RegisterAumidAndComServer<MyNotificationActivator>("WindowsNotifications.SomeApp");
        DesktopNotificationManagerCompat.RegisterActivator<MyNotificationActivator>();

【讨论】:

    猜你喜欢
    • 2023-03-25
    • 2022-06-16
    • 1970-01-01
    • 2018-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    相关资源
    最近更新 更多