如何为 Windows Toast 注册协议? [英] How register a protocol for a Windows toast?

查看:53
本文介绍了如何为 Windows Toast 注册协议?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为 Windows Toast 注册协议?在来自 https://blogs.msdn.microsoft.com/tiles_and_toasts/2015/07/02/adaptive-and-interactive-toast-notifications-for-windows-10/:

How can I register a protocol for a Windows toast ? In the sample from https://blogs.msdn.microsoft.com/tiles_and_toasts/2015/07/02/adaptive-and-interactive-toast-notifications-for-windows-10/:

<toast launch="app-defined-string">
  <visual>
    <binding template="ToastGeneric">
      <text>Restaurant suggestion...</text>
      <text>We noticed that you are near Wasaki. Thomas left a 5 star rating after his last visit, do you want to try it?</text>
    </binding>
  </visual>
  <actions>
    <action activationType="foreground" content="Reviews" arguments="reviews" />
    <action activationType="protocol" content="Show map" arguments="bingmaps:?q=sushi" />
  </actions>
</toast>

他们展示了一个新的原型bingmaps".如何添加新协议?

They show a new proto "bingmaps". How can I add a new protocol ?

实际上我在注册表中添加了这些键:

Actually I add these keys in the registry:

HKEY_CLASSES_ROOT\myProto
    (default) = (REG_SZ) "URL:myProto Protocol"
    shell/
        open/
            command = (REG_SZ) "...myExe.exe %1"

HKCU\SOFTWARE\Classes\myProto
    (default) = (REG_SZ) "URL:myProto Protocol"
    shell/
        open/
            command = (REG_SZ) "...myExe.exe %1"

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\Shell\Associations\UrlAssociations\myProto\UserChoice
    ProgId = (REG_SZ) myProto

确切的cmd命令:

reg add 'HKEY_CLASSES_ROOT\myProto' /ve /t REG_SZ /d 'URL:myProto Protocol' /f
reg add 'HKEY_CLASSES_ROOT\myProto' /v 'URL Protocol' /f
reg add 'HKEY_CLASSES_ROOT\myProto\shell\open\command' /ve /d '...myExe.exe "%1"' /f

reg add 'HKCU\SOFTWARE\Classes\myProto' /ve /t REG_SZ /d 'URL:myProto Protocol' /f
reg add 'HKCU\SOFTWARE\Classes\myProto' /v 'URL Protocol' /f
reg add 'HKCU\SOFTWARE\Classes\myProto\shell\open\command' /ve /d '...myExe.exe "%1"' /f

reg add 'HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\Shell\Associations\UrlAssociations\myProto\UserChoice' /v 'ProgId' /t REG_SZ /d 'myProto' /f

它适用于所有地方,除了吐司...为什么?我的吐司:

It works everywhere except for the toast... Why ? My Toast:

<toast launch="app-defined-string">
  <visual>
    <binding template="ToastGeneric">
      <text>Restaurant suggestion...</text>
      <text>We noticed that you are near Wasaki. Thomas left a 5 star rating after his last visit, do you want to try it?</text>
    </binding>
  </visual>
  <actions>
    <action activationType="foreground" content="Reviews" arguments="reviews" />
    <action activationType="protocol" content="Show map" arguments="myProto:test" />
  </actions>
</toast>

编辑 2017-05-19

我使用这些参数

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\my-cool-app]
@="URL:my-cool-app"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\my-cool-app\shell\open\command]
@="cmd /c \"echo A > C:\\Users\\Public\\a.log\""

[HKEY_CURRENT_USER\SOFTWARE\Classes\my-cool-app]
@="URL:my-cool-app"
"URL Protocol"=""

[HKEY_CURRENT_USER\SOFTWARE\Classes\my-cool-app\shell\open\command]
@="cmd /c \"echo A > C:\\Users\\Public\\a.log\""

以及以下 PS 脚本:

And the following PS script:

$toastXml = @"
<toast launch="my-cool-app:arguments_for_my_app" activationType="protocol">
  <visual>
    <binding template="ToastGeneric">
      <text>My test app using protocol</text>
    </binding>
  </visual>
</toast>
"@
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]
[Windows.UI.Notifications.ToastNotification, Windows.UI.Notifications, ContentType = WindowsRuntime]

$xml = New-Object Windows.Data.Xml.Dom.XmlDocument
$xml.LoadXml(([xml]$toastXml).OuterXml)
$toast = [Windows.UI.Notifications.ToastNotification]::new($xml)
$toast.Tag = "PowerShell"
$toast.Group = "PowerShell"
$toast.ExpirationTime = [DateTimeOffset]::Now.AddMinutes(5)

$notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("PowerShell")
$notifier.Show($toast);

推荐答案

尝试使用 (default) = (REG_SZ) "URL:myProto" 而不是 (default) = (REG_SZ)"URL:myProto 协议"

你可能想看看我的文章如何做到这一点:https://www.codeproject.com/Articles/1187127/Windows-toast-notifications-without-a-COM-server?msg=5395948#xx5395948xx

You might want to check out my article how to do that: https://www.codeproject.com/Articles/1187127/Windows-toast-notifications-without-a-COM-server?msg=5395948#xx5395948xx

这篇关于如何为 Windows Toast 注册协议?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆