2017-10-18 83 views
3

我有一个PowerShell代码,我把它叫做做的吐司通知.NET参考,它的作品擅长以前的更新。但得到的窗口时10秋季创(FCU)更新,它走了,同样的代码不是现在的工作:
Toast通知不工作在Windows秋天创更新

$app = "HTML Report" 
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] 

$Template = [Windows.UI.Notifications.ToastTemplateType]::ToastImageAndText01 

#Gets the Template XML so we can manipulate the values 
[xml]$ToastTemplate = ([Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent($Template).GetXml()) 

[xml]$ToastTemplate = @" 
<toast launch="app-defined-string"> 
    <visual> 
    <binding template="ToastGeneric"> 
     <text>DNS Alert...</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="background" content="Remind me later" arguments="later"/> 
    </actions> 
</toast> 
"@ 

$ToastXml = New-Object -TypeName Windows.Data.Xml.Dom.XmlDocument 
$ToastXml.LoadXml($ToastTemplate.OuterXml) 

$notify = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($app) 

$notify.Show($ToastXml) 
+2

的[burnttoast模块(https://github.com/Windos/BurntToast)具有约1709的一些说明和变化对于AppIDs。这是[GitHub提交](https:// github。com/Windos/BurntToast/commit/674b80c9fbbd689a729c1fd2c3dedd386843a5a4)与他们所做的更改,希望有助于。 – BenH

+0

我使用自己的代码,他说他的代码 – Aso

回答

8

正如评论所说,这是一件最近有BurntToast模块中加以解决。还有一个blog post也伴随着这个变化,但我会尽我所能在这里总结这个答案的完整性。

这归结为“应用程序用户模型ID”(以下简称的AppId),那你提供的Toast通知管理器。

严格地说,这的AppId需要匹配一个AppID在正坐在你的开始菜单快捷方式包埋。这一直是这种情况,但有一种漏洞允许任何老版本的Windows AppId在旧版本的Windows 10中。

尽管它让我们这些从脚本创建Toast的人感到厌倦,但这个漏洞已经关闭,我们的AppIds,就像Fall Creators Update一样,需要“真实”。

您可以通过运行找到有效AppIds的列表:

Get-StartApps 

我选择默认保存到一个PowerShell.exe:

{1AC14E77-02E7-4E5D-B744 -2EB1AE5198B7} \ WindowsPowerShell \ V1.0 \ powershell.exe

应当注意的是,你还需要配置一些(包括PowerShell的),使他们的祝酒词实际上是DISPLA当他们超时时在行动中心工作。

您可以通过“设置”做到这一点:

设置 - >系统 - >通知&行动 - >的PowerShell(向下滚动,你必须需要已将至少一个吐司它出现) - >在行动中心显示通知。

PowerShell notification settings

您也可以通过注册表为此,HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings

对于PowerShell的例子下,您将添加一个DWORD(设置为1)所谓ShowInActionCenter下:

HKCU :\ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Notifications \ Settings {1AC14E77-02E7-4E5D-B744-2EB1AE5198B7} \ WindowsPowerShell \ v1.0 \ powershell.exe \

如果你想要做自己的AppId,你需要看看如何创建一个shortcut with an AppId,或通过AppxManifest.xml创建一个虚拟UWP应用。我仍然在以一种用户友好的方式进行其中一项工作。

+0

谢谢Mr. Windos。我很感谢你的回答。但仍然不适合我。在我的“通知和操作”中,“PowerShell”不存在。我也创建了这些注册表{Keys,Values}。请在您的桌面上查看我的代码。 – Aso

+1

@因此,当我将代码的第一行更改为'$ app ='{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7} \ WindowsPowerShell \ v1.0 \ powershell.exe''时,它对我来说很合适。 – Windos

+0

你可以发布你的固定代码吗? – Aso