让AI帮实现了一下,调用 PowerShell
|
| 右下角通知 | 文本型 | | |
| 程序名称 | 文本型 | | | | 通知标题 | 文本型 | | | | 通知内容第一行 | 文本型 | | | | 通知内容第二行 | 文本型 | | | |
| 变量名 | 类 型 | 静态 | 数组 | 备 注 | | 命令文本 | 文本型 | | | | 返回文本 | 文本型 | | | 写到文件 (取运行目录 () + “\notice.ps1”, 到字节集 ( #常量1 )) 命令文本 = “powershell.exe -ExecutionPolicy Bypass -File notice.ps1 -AppName ” + 程序名称 + “ -Title ” + 通知标题 + “ -Line1 ” + 通知内容第一行 如果真 (是否为空 (通知内容第二行 ) = 假) 命令文本 = 命令文本 + “ -Line2 ” + 通知内容第二行 返回文本 = 系统_取DOS执行结果 (命令文本, )返回 (返回文本 )
下面是常量1的内容
[PowerShell] 纯文本查看 复制代码 # showtoast_multiline_safe.ps1
param(
[string]$AppName = "MyApp",
[string]$Title,
[string]$Line1, # 第一行内容
[string]$Line2 = "" # 第二行内容 (可选,默认为空)
)
# 加载 WinRT 命名空间
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
# 使用支持多行的 ToastText04 模板
$template = [Windows.UI.Notifications.ToastTemplateType]::ToastText04
$xml = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent($template)
# 获取文本节点集合
$textNodes = $xml.SelectNodes("//text")
$count = $textNodes.Count
# 填充文本节点 - 安全地检查索引是否存在
if ($count -gt 0) { $textNodes.Item(0).AppendChild($xml.CreateTextNode($Title)) | Out-Null } # 标题
if ($count -gt 1) { $textNodes.Item(1).AppendChild($xml.CreateTextNode($Line1)) | Out-Null } # 第一行内容
if ($count -gt 2) { $textNodes.Item(2).AppendChild($xml.CreateTextNode($Line2)) | Out-Null } # 第二行内容
# 创建并显示通知
$toast = [Windows.UI.Notifications.ToastNotification]::new($xml)
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($AppName).Show($toast)
|