0

I am creating a task in task scheduler with powreshell with the argument below. I'm making a pop up message come to a logged in user at 11 AM every day for two weeks.

-WindowStyle hidden -Command "& {[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms'); [System.Windows.Forms.MessageBox]::Show('message body here','window title here')}"

does anyone know if their are options to add to this to bring the message to the front like an annoying popup? meaning, if you were working in excel for example, this popup would be front and center on top of the spread sheet you are working on so you would have to click on it to make it go away. also, looking to increase font size as well.

just seeing if there are options to add this in the arguments via the task scheduler.

thank you!

0

No that class in the base class libraries is not extensible. You should create your own form/dialog. A few examples:

https://www.codeproject.com/Articles/601900/FlexibleMessageBox-A-flexible-replacement-for-the

https://community.idera.com/database-tools/powershell/powertips/b/tips/posts/creating-simple-custom-dialog

https://docs.microsoft.com/en-us/powershell/scripting/samples/creating-a-custom-input-box?view=powershell-7.1


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
}
1
  • Hey Greg. Thanks for the follow up. I saw lots of examples like yours online. I was hoping I could just add an argument to the existing class. I will do what you suggested. thank you Sir!! – lark2056 Jan 21 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.