Login Script to Popup a Windows Form

Copper Contributor

Hi, 

 

I am trying to popup a form via a PowerShell login script (User Configuration) but the form is getting supressed even when using: 

$form.Topmost = $true

Does anyone know a way via PowerShell I can force the form to popup? I'd like to avoid using the "Run logon scripts visible" setting since its not the only script running and the form will only display when certain criteria are met.

 

I can't post my actual script but its a pretty generic form much like this: 

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(300,200)
$form.StartPosition = 'CenterScreen'

$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(280,20)
$label.Text = 'Please enter the information in the space below:'
$form.Controls.Add($label)

$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Location = New-Object System.Drawing.Point(10,40)
$textBox.Size = New-Object System.Drawing.Size(260,20)
$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
}

   

Any help would be appreciated. 

 

Thanks

2 Replies
Hi

>I'd like to avoid using the "Run logon scripts visible" setting since its not the only script running and the form will only display when certain criteria are met.

I understand - but that seems exactly the problem here

#Start the Process > Window is shown
Start-Process powershell.exe "-noprofile .\topmost.ps1"

#Start Process hidden Window > No Window is shown
Start-Process powershell.exe "-noprofile .\topmost.ps1" -WindowStyle hidden

Does exactly what told: "Run logon scripts visible = false" > Do not show any windows ;)

Regards
Andres
Hi,

Even with this GPO setting turned on the form is minimised and you have to click it in the start bar to get it to display. I need the form to popup for the user.