You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为WinUI 3程序设置自定义通知注册表ID?

为未打包WinUI 3程序设置自定义通知注册表标识

问题原因

未打包的WinUI 3桌面应用默认没有注册固定的应用用户模型ID(AUMID),系统会自动生成随机GUID作为通知设置的标识。要实现类似SentinelOne.WinAgent的自定义标识,需要手动注册AUMID并关联到你的应用。

解决方案步骤

1. 定义自定义AUMID

选择一个符合反向域名格式的唯一标识,比如YourCompany.YourAppName(替换为你的公司和应用名称)。

2. 注册AUMID到注册表

在应用启动时(建议在初始化通知管理器之前),将AUMID注册到HKEY_CURRENT_USER注册表项,关联你的EXE路径。以下是C#代码示例:

using Microsoft.Win32;
using System.Reflection;

private void RegisterCustomAumid(string aumid)
{
    var exePath = Assembly.GetEntryAssembly()?.Location;
    if (string.IsNullOrEmpty(exePath))
        return;

    using var key = Registry.CurrentUser.CreateSubKey($"Software\\Classes\\AppUserModelId\\{aumid}");
    key?.SetValue(string.Empty, "你的应用显示名称"); // 设置默认值为应用名称
    key?.SetValue("Path", exePath); // 关联EXE路径
}

3. 修改AppNotificationManager初始化代码

调用Register方法时传入自定义的AUMID,替换原来无参数的Register():

public void Init()
{
    const string CustomAumid = "YourCompany.YourAppName"; // 替换成你的自定义AUMID
    RegisterCustomAumid(CustomAumid);

    AppNotificationManager notificationManager = AppNotificationManager.Default;
    notificationManager.NotificationInvoked += OnNotificationInvoked;

    // 使用自定义AUMID注册通知管理器
    notificationManager.Register(CustomAumid);

    m_isRegistered = true;
}

4. 验证效果

运行应用后,打开注册表编辑器,导航到HKEY_USERS\<你的SID>\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\,你会看到以你自定义AUMID命名的注册表项,替代了原来的随机GUID。

补充说明

  • 你现有appxmanifest配置主要用于打包应用的COM激活注册,未打包场景下需要额外的AUMID注册表配置才能固定通知标识。
  • 注册表操作针对HKEY_CURRENT_USER,无需管理员权限,不会影响其他用户。

内容的提问来源于stack exchange,提问作者Fabio

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 17:54:54