I have a powershell script that pops up a simple win form as a job starts, and then closes when the job ends. This form runs fine and as expected out of ISE or calling from a .ps1.
However, if I push through GPO, the 'label' section of the form does not seem to run. It shows the desktop background in its place and never loads. The form shows eventually changes from its title to (not responding). However, the form does close as it should when the job is complete.
I have tried multiude of font sizes, label sizes, plain fonts, etc, but when when ran via GPO it doesn't work properly.
I don't know why GP would make a difference, so I have to assume its something in the script.
Does anybody know why this would be?
$file = (get-item '\\server\file.png')
[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") |Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") |Out-Null
Add-Type -AssemblyName System.Windows.Forms
$Form = New-Object system.Windows.Forms.Form
$Form.Text = "Sample Form"
$Image = [system.drawing.image]::FromFile($file)
$Form.BackgroundImage = $Image
$Form.BackgroundImageLayout = "None"
$Form.Width = '300'
$Form.Height = '200'
$Font = New-Object System.Drawing.Font("Times New Roman",12,[System.Drawing.FontStyle]::Italic)
$Form.Font = $Font
$Label = New-Object System.Windows.Forms.Label
$Label.Text = "This form is a test."
$Label.BackColor = "Transparent"
$Label.AutoSize = $True
$Form.Controls.Add($Label)
$Form.Show()
$Form.Add_FormClosed({
$Label.Dispose()
$Form.Dispose()
})
$job=Start-Job -name CCC -filepath '\\server\ccc.ps1' | wait-job
$Form.Close()
$job = {
$max = 5
foreach ($i in $(1..$max)) {
sleep 1 }
}