Skip to content

Instantly share code, notes, and snippets.

@altrive
Created January 14, 2014 20:31
Show Gist options
  • Save altrive/8425136 to your computer and use it in GitHub Desktop.
Save altrive/8425136 to your computer and use it in GitHub Desktop.
$ErrorActionPreference = "Stop"
#Need to install Nuget packages before execute
Add-Type -Path (Join-Path (Split-Path $profile -Parent) "packages\Windows7APICodePack-Core.1.1.0.0\lib\Microsoft.WindowsAPICodePack.dll" -Resolve)
Add-Type -Path (Join-Path (Split-Path $profile -Parent) "\packages\Windows7APICodePack-Shell.1.1.0.0\lib\Microsoft.WindowsAPICodePack.Shell.dll" -Resolve)
<#
#TODO: Define Interop code to register shortcut with appid
$referencedAssemblies = @(
[MS.WindowsAPICodePack.Internal.PropVariant].Assembly.FullName,
[Microsoft.WindowsAPICodePack.Shell.PropertySystem.SystemProperties].Assembly.FullName
)
Add-Type -ReferencedAssemblies @([MS.WindowsAPICodePack.Internal.PropVariant].Assembly.FullName) -TypeDefinition @"
//省略
"@
#>
$APP_ID = "ISEToast"
$shortcutPath = [Environment]::GetFolderPath([Environment+SpecialFolder]::ApplicationData) + "\Microsoft\Windows\Start Menu\Programs\ISEToast.lnk";
if (![IO.File]::Exists($shortcutPath))
{
#TODO: Create shortcut
<#
#Create shortcut to StartMenu with AppId(ISEToast)
$exePath = [Diagnostics.Process]::GetCurrentProcess().MainModule.FileName
#$newShortcut = [IShellLinkW](New-Object CShellLink)
[IShellLinkW]$newShortcut = [Utility]::GetShellLinkW()
$newShortcut.SetPath($exePath)
$newShortcut.SetArguments("")
$newShortcutProperties = [IPropertyStore] $newShortcut;
try
{
$appId = new PropVariant($APP_ID)
$newShortcutProperties.SetValue([Microsoft.WindowsAPICodePack.Shell.PropertySystem.SystemProperties]::System.AppUserModel.ID, $appId);
$newShortcutProperties.Commit()
}
finally
{
if ($appId -ne $null){
$appId.Dispose()
}
}
$newShortcutSave = [IPersistFile] $newShortcut;
$newShortcutSave.Save($shortcutPath, $true);
#>
}
$title = "タイトル"
$message = "メッセージ。。。。。"
#Load WinRT types
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
#ToastTemplateType <http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.notifications.toasttemplatetype.aspx>
$toastXml = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastImageAndText04)
#Convert to .NET type
$toastXml = [xml] $toastXml.GetXml()
$imageElements = $toastXml.GetElementsByTagName("image");
$imageElements[0].Attributes.GetNamedItem("src").Value = "file:///" + "";
#Fill in the text elements
$stringElements = $toastXml.GetElementsByTagName("text")
$stringElements[0].AppendChild($toastXml.CreateTextNode($title)) > $null
$stringElements[1].AppendChild($toastXml.CreateTextNode($message)) > $null
#Convert to WinRT type
$x = New-Object Windows.Data.Xml.Dom.XmlDocument
$x.LoadXml($toastXml.OuterXml)
$toast = New-Object Windows.UI.Notifications.ToastNotification($x)
<#
$toast.add_Activated({ param ($object, $args) Write-Host "Toast notification activated" }) > $null
$toast.add_Dismissed({ param ($object, $args) Write-Host "Toast notification dismissed" }) > $null
$toast.add_Failed({ param ($object, $args) Write-Host "Toast notification failed" }) > $null
#>
$notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($APP_ID)
$notifier.Show($toast)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment