在 powershell 中的弹出窗口/消息上添加颜色

问题描述 投票:0回答:1

我想用红色写一些单词来测试当我远程连接到电脑时将部署/激活的消息。 我尝试过放在开头:

Set-PSReadLineOption -Colors @{ ContinuationPrompt = '红色' } powershell -WindowStyle 隐藏 -Command "& {[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms');...

这不起作用。

并将函数 foregroundcolor 放在但给我错误。

powershell -ForegroundColor Red -WindowStyle hide -Command "& {[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms'); ...

这是代码,消息弹出并且运行良好,我只想在文本上添加颜色。 我想将“请不要触摸您的键盘或鼠标”这句话写成红色,或者如果不可能将整个文本写成红色。

powershell -WindowStyle hide -Command "& {[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms'); [System.Windows.Forms.MessageBox]::Show('IT 部门已连接到您的PC 请不要触摸键盘或鼠标,谢谢','测试/消息')}"

powershell deployment system-administration
1个回答
0
投票

据我所知,您无法更改MessageBox中的字体颜色。但是,您可以使用警告图标,如下所示:

powershell -WindowStyle hidden -Command "& {
[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms');
[System.Windows.Forms.MessageBox]::Show('IT department has connected to your PC please dont touch your keyboard or mouse, thank you','TEST/Message',[System.Windows.Forms.MessageBoxButtons]::OK,[System.Windows.Forms.MessageBoxIcon]::Stop)
}"

© www.soinside.com 2019 - 2024. All rights reserved.