我正在使用 powreshell 在任务计划程序中创建任务,参数如下。我让登录用户每天上午 11 点弹出一条消息,持续两周。
-WindowStyle 隐藏 -Command "& {[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms'); [System.Windows.Forms.MessageBox]::Show('消息正文在此','窗口标题在此')}"
有人知道是否可以添加选项,将消息像烦人的弹出窗口一样放在最前面吗?意思是,例如,如果您在 Excel 中工作,此弹出窗口将位于您正在处理的电子表格顶部的正中央,因此您必须单击它才能使其消失。此外,还希望增加字体大小。
只是看看是否有选项可以通过任务计划程序将其添加到参数中。
谢谢你!
答案1
不,基类库中的该类不可扩展。您应该创建自己的表单/对话框。以下是一些示例:
https://www.codeproject.com/Articles/601900/FlexibleMessageBox-A-flexible-replacement-for-the
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$form = New-Object System.Windows.Forms.Form
$form.Text = 'Data Entry Form'
$form.Size = New-Object System.Drawing.Size(500,200)
$form.StartPosition = 'CenterScreen'
$form1.Font = New-Object System.Drawing.Font($form1.font.Name,14)
$okButton = New-Object System.Windows.Forms.Button
$okButton.Location = New-Object System.Drawing.Point(75,120)
$okButton.Size = New-Object System.Drawing.Size(75,23)
$okButton.Text = 'OK'
$okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $okButton
$form.Controls.Add($okButton)
$cancelButton = New-Object System.Windows.Forms.Button
$cancelButton.Location = New-Object System.Drawing.Point(150,120)
$cancelButton.Size = New-Object System.Drawing.Size(75,23)
$cancelButton.Text = 'Cancel'
$cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $cancelButton
$form.Controls.Add($cancelButton)
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,20)
$label.Size = New-Object System.Drawing.Size(480,20)
$label.Text = 'Please enter the information in the space below:'
$label.Font = New-Object System.Drawing.Font($form1.font.Name,14)
$form.Controls.Add($label)
$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Location = New-Object System.Drawing.Point(10,50)
$textBox.Size = New-Object System.Drawing.Size(460,20)
$textBox.Font = New-Object System.Drawing.Font($form1.font.Name,14)
$form.Controls.Add($textBox)
$form.Topmost = $true
$form.Add_Shown({$textBox.Select()})
$result = $form.ShowDialog()
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
{
$x = $textBox.Text
$x
}