如何为Windows Toast注册协议? 来自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”。 如何添加新协议?
实际上我在注册表中添加了这些键:
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
除了吐司之外它无处不在......为什么? 我的祝酒词:
<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脚本:
$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);
答案 0 :(得分:1)
尝试使用(default) = (REG_SZ) "URL:myProto"
代替(default) = (REG_SZ) "URL:myProto Protocol"
您可能想查看我的文章如何执行此操作: https://www.codeproject.com/Articles/1187127/Windows-toast-notifications-without-a-COM-server?msg=5395948#xx5395948xx
答案 1 :(得分:0)
# Persist the Settings notifications to prevent to immediately disappear from Action Center
if (-not (Test-Path -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel"))
{
New-Item -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Force
}
New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Name ShowInActionCenter -PropertyType DWORD -Value 1 -Force
# Register the "WindowsCleanup" protocol to be able to run the scheduled task upon clicking on the "Run" button
if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup))
{
New-Item -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Force
}
New-itemproperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name "(Default)" -PropertyType String -Value "url:WindowsCleanup" -Force
New-itemproperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name "URL Protocol" -Value "" -Force
New-itemproperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name EditFlags -PropertyType DWord -Value 2162688 -Force
if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\Shell\Open\command))
{
New-item -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\Shell\Open\command -Force
}
# If "Run" clicked run the "Windows Cleanup" task
New-itemproperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\Shell\Open\command -Name "(Default)" -PropertyType String -Value 'powershell.exe -Command "& {Start-ScheduledTask -TaskPath ''\Sophia Script\'' -TaskName ''Windows Cleanup''}"' -Force