我一直在使用本博客中的 PowerShell 脚本(脚本位于底部)为用户创建一个消息框,告诉他们他们的 VPN 用户名是什么。我想要做的是添加一个复制按钮,以便用户可以复制用户名。下面是在脚本末尾添加的一些额外代码,用于启动消息框。目前只显示一个“确定”按钮。我根本不了解 WPF,我试图保持在博客作者脚本的框架内。我还附上了消息框的图片。
# Read content of VPN_username.txt, if it exists.
if (Test-Path -Path "$env:SystemDrive\Temp\VPN_username.txt") {
$VPNUserName = Get-Content -Path "$env:SystemDrive\Temp\VPN_username.txt" -Force
}
# Load WPF assembly
Add-Type -AssemblyName PresentationFramework
# Create a richtextbox to display the completion summary with hyperlinks
$RTB = New-Object System.Windows.Controls.RichTextBox
$RTB.Padding = 5
$RTB.IsDocumentEnabled = $true
$RTB.IsReadOnly = $true
$RTB.BorderThickness = 0
$RTB.MaxWidth = 370
$RTB.FontFamily = "Segui"
$RTB.FontSize = 14
$FlowDocument = New-Object System.Windows.Documents.FlowDocument
$Paragraph = New-Object System.Windows.Documents.Paragraph
$Run = New-Object System.Windows.Documents.Run
$Run.Text = "The VPN username that you last used is $VPNUserName"
$Paragraph.AddChild($Run)
$FlowDocument.AddChild($Paragraph)
$RTB.AddChild($FlowDocument)
# Display the messagebox.
New-WPFMessageBox -Content $RTB -Title "Cisco Secure Client Upgrade" -TitleFontSize 24 -TitleBackground MidnightBlue -TitleTextForeground White -Sound 'Windows Notify'