Last active
July 13, 2016 07:46
-
-
Save guitarrapc/8426022 to your computer and use it in GitHub Desktop.
toast sample in PowerShell not yet finished;
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Code conversion from C# to PowerShell | |
# http://msdn.microsoft.com/en-us/library/windows/apps/hh802768.aspx | |
# nuget Windows 7 API Code Pack -Shell | |
# http://nugetmusthaves.com/Package/Windows7APICodePack-Shell | |
# Install-Package Windows7APICodePack-Shell | |
Add-Type -Path .\Microsoft.WindowsAPICodePack.dll | |
Add-Type -Path .\Microsoft.WindowsAPICodePack.Shell.dll | |
# create toast template TO xml | |
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null | |
[xml]$toastXml = ([Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastImageAndText04)).GetXml() | |
<# | |
# これでもいいが template type の違いに注意 | |
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null | |
$toastTemplate = [Windows.UI.Notifications.ToastTemplateType]::ToastImageAndText01 | |
[xml]$toastXml = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent($toastTemplate).GetXml() | |
#> | |
# message to show on toast | |
$stringElements = $toastXml.GetElementsByTagName("text") | |
for ($i = 0; $i -lt $stringElements.Count; $i++) | |
{ | |
$stringElements[$i].AppendChild($toastXml.CreateTextNode("Line " + $i)) > $null | |
} | |
<# | |
# こっちもあり | |
$stringElements = $toastXml.GetElementsByTagName("text") | select -First 1 | |
$stringElements.AppendChild($toastXml.CreateTextNode("Test Toast Notification")) > $null | |
#> | |
# no image | |
$imageElements = $toastXml.GetElementsByTagName("image") | |
$imageElements[0].src = "file:///" + "" | |
# convert from System.Xml.XmlDocument to Windows.Data.Xml.Dom.XmlDocument | |
$windowsXml = New-Object Windows.Data.Xml.Dom.XmlDocument | |
$windowsXml.LoadXml($toastXml.OuterXml) | |
$APP_ID = "hoge" | |
$shortcutPath = [Environment]::GetFolderPath([Environment+SpecialFolder]::ApplicationData) + "\Microsoft\Windows\Start Menu\Programs\hoge.lnk"; | |
# send toast notification | |
$toast = New-Object Windows.UI.Notifications.ToastNotification ($windowsXml) | |
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($APP_ID).Show($toast) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO
Required to use SHGetPropertyStoreForWindows from IPropertyStore object to set System.AppUserModel.ID
http://msdn.microsoft.com/en-us/library/windows/apps/dd391569.aspx