Show Form During Logon Script

Welcome Forums General PowerShell Q&A Show Form During Logon Script

This topic contains 3 replies, has 3 voices, and was last updated by

10 months ago.

  • Author
  • #104719

    Topics: 2
    Replies: 3
    Points: 0
    Rank: Member

    I have a powershell logon script via GPO. I would like to show a form when the script runs. Works great from the ISE but doesn't do anything during the logon script.

    Thanks for any help!

    Add-Type -AssemblyName System.Windows.Forms

    $form = New-Object System.Windows.Forms.Form
    $form.Text = ""
    $form.Size = New-Object System.Drawing.Size(400, 800) #width, height
    $form.Font = New-Object System.Drawing.Font("Comic Sans MS",16,[System.Drawing.FontStyle]::Regular)
    $form.MinimizeBox = $False
    $form.MaximizeBox = $False
    $form.WindowState = "Normal" #Maximized, Minimized, Normal
    $form.SizeGripStyle = "Hide" #Auto, Hide, Show
    $form.ShowInTaskbar = $False
    $form.Opacity = 1.0 #1.0 is fully opaque; 0.0 is invisible
    $form.StartPosition = "CenterScreen" # CenterScreen, Manual, WindowsDefaultLocation, WindowsDefaultBounds, CenterParent

    $label1 = New-Object System.Windows.Forms.label
    $label1.BackColor = "Transparent"
    $label1.BorderStyle = "None"
    $label1.Location = New-Object System.Drawing.Point(1, 375) #left, top
    $label1.Text = "Test Line 1"
    $label1.TextAlign = "MiddleCenter"
    $label1.Width = 800


  • #104755

    Topics: 13
    Replies: 4872
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    Yeah, the ISE is not a good "testbed." But there's a further complexity with logon scripts where PowerShell doesn't get front-most execution priority. There's not actually much you can do about that, as it's not PowerShell's fault, but rather the way GPs are processed and given system access.

    Is the goal here to collect information, or just display a message?

  • #104791

    Topics: 2
    Replies: 929
    Points: 1,594
    Helping Hand
    Rank: Community Hero

    Ditto on the GPO preference and the .ps1 priority.
    Your post runs as expected in the ISE/ConsoleHost/VSCode/PSStudio, and even from a scheduled task.
    So, something else is the catch22.

  • #104819

    Topics: 2
    Replies: 3
    Points: 0
    Rank: Member

    Thanks for the replies. In this case the solution was simple...I just added $form.topmost to the code.

    Thanks again!

The topic ‘Show Form During Logon Script’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort