Trying to add popup but bad size when using with PSAPPDeploytoolkit


I added a popup to allow a user to read a message before continuing.
The popup works fine in a powershell, but when I integrate it into the Psappdeploytoolkit, the size is no longer correct.

I don’t understand why, even trying to change it, it doesn’t change anything …

Version 3.7.0 and 3.8.4 tested, same behavior.

Do you have an idea ?

you might have to modify the code in AppDeployToolkitMain.ps1 to either make the dialog bigger or shrink the size of the fonts.

The easiest way to get around this problem is to reword your messages or break it up into 2 popups.

I can’t add another popup for this.
Do you know what i should modify in main.ps1 ?

I don’t find the good parameter i need to modify.

I can’t guess which function you are using to do the popup either.
Help me to help you.

Here the function to show the popup :

Function CustomPopup 

               Param (


               Begin {
                              ## Get the name of this function and write header
                              [string]${CmdletName} = $PSCmdlet.MyInvocation.MyCommand.Name
                              Write-FunctionHeaderOrFooter -CmdletName ${CmdletName} -CmdletBoundParameters $PSBoundParameters -Header

    Process {

                             #region Import the Assemblies
                             #endregion Import Assemblies
                             #region Generated Form Objects
                             $MainForm = New-Object 'System.Windows.Forms.Form'
                    $panelBanner = New-Object 'System.Windows.Forms.Panel'
                    $panelButton = New-Object 'System.Windows.Forms.Panel'
                    $labelUnsaved = New-Object 'System.Windows.Forms.Label'
                    $labelMain = New-Object 'System.Windows.Forms.Label'
                    $labelInstallNowMessage = New-Object 'System.Windows.Forms.Label'
                    $ButtonApplyNow = New-Object 'System.Windows.Forms.Button'
                    $InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
                    $NotifyIcon = New-Object 'System.Windows.Forms.NotifyIcon'
                    $ContextMenu = New-Object 'System.Windows.Forms.ContextMenu'
                    $ShowItem = New-Object 'System.Windows.Forms.MenuItem'
                    $MinimizeItem = New-Object 'System.Windows.Forms.MenuItem'
                    $MyDir = [System.IO.Path]::GetDirectoryName($myInvocation.ScriptName)
                             #endregion Generated Form Objects

                #region Text
                        $TextButton = "Update Now"
                        $Text = "
Software to update now -  the new software will be updated in a few minutes.

Name of the software must be now updated in order to continue the to use it on your PC.

Please save your work and close all open files/documents before proceeding.

The update will start when you have clicked on the update now and your machine will be restarted after the update.

                        $TextSettingsMain = 'Microsoft Sans Serif, 11pt'
                        $TextSettingsUnsaved = 'Microsoft Sans Serif, 11pt, style=Bold'
                        $TextUnsavedLocation = '24, 230'


                        $MainForm.WindowState = "Normal"
                        $MainForm.WindowState = "minimized"
                    [scriptblock]$NotifyIcon_MouseDoubleClick = {
                        $MainForm.WindowState = "Normal"
                        Write-log -message "[Update Now] button clicked"
                        $resultPopUp = [System.Windows.MessageBox]::Show("Are you sure ?",'Update Software','YESNO','Warning','NO')
                        If($resultPopUp -eq "YES")
                            Write-log -message "User selected YES"
                            Write-log -message "User selected NO"


                                            # --End User Generated Script--
                             #region Generated Events
                                            #Correct the initial state of the form to prevent the .Net maximized form issue
                                            $MainForm.WindowState = $InitialFormWindowState
                                            #Store the control values
                                            #Remove all event handlers from the controls
                                            catch [Exception]
                                            { }
                             #endregion Generated Events
                             #region Generated Form Code

                #region Main Form
                    # Main Form
                    [string]$invokingScript = (Get-Variable -Name 'MyInvocation').Value.ScriptName
                    [string]$scriptParentPath = Split-Path -Path $invokingScript -Parent
                    $Icon = New-Object System.Drawing.Icon("$scriptParentPath\AppDeployToolkit\AppDeployToolkitLogo.ico")
                             #$MainForm.AutoScaleDimensions = '6, 13'
                             #$MainForm.AutoScaleMode = 'Font'
                             $MainForm.BackColor = '#FFFFFF'
                             $MainForm.ClientSize = '700, 450'
                    $MainForm.ControlBox = $False #Mettre False pour empecher de fermer le popup
                             $MainForm.Name = 'MainForm'
                    $MainForm.Icon = $Icon
                             $MainForm.ShowIcon = $False
                    $MainForm.FormBorderStyle = 'FixedDialog'
                             $MainForm.ShowInTaskbar = $False #Mettre False pour le déploiement
                             $MainForm.StartPosition = 'CenterScreen'
                             $MainForm.Text = 'Update Software - WARNING - You must close any files opened'
                             $MainForm.TopMost = $True
                    #$MainForm.AutoSize = $True
                #region panel
                    # panelButton
                             $panelButton.BackColor = '39,80,155'
                             $panelButton.Location = '0, 370'
                             $panelButton.Name = 'panelButton'
                             $panelButton.Size = '700, 80'
                             $panelButton.TabIndex = 10
                    # panelBanner
                    $Image = [System.Drawing.Image]::FromFile("$scriptParentPath\AppDeployToolkit\AppDeployToolkitBanner.png")
                    $panelBanner.BackgroundImage = $Image
                    $panelBanner.BackgroundImageLayout = "None"
                             $panelBanner.BackColor = '39, 80, 155'
                             $panelBanner.Location = '0, 0'
                             $panelBanner.Name = 'panelBanner'
                             $panelBanner.Size = '700, 80'
                             $panelBanner.TabIndex = 9
                #region label
                    # labelMain
                             $labelMain.Font = $TextSettingsMain
                             $labelMain.Location = '24, 90'
                             $labelMain.Name = 'labelMain'
                             $labelMain.Size = '666, 350'
                             $labelMain.TabIndex = 2
                             $labelMain.Text = $Text
                #region Notification
                    # NotifyIcon
                    $ShowItem.Text = "Show"
                    $MinimizeItem.Text = "Minimize"
                    $NotifyIcon.Icon = $Icon
                    $NotifyIcon.ContextMenu = $ContextMenu
                    $NotifyIcon.Visible = $True
                #endregion Label
                #region Button
                    # ButtonApplyNow
                             $ButtonApplyNow.Font = 'Microsoft Sans Serif, 10pt, style=Bold'
                    $ButtonApplyNow.ForeColor = 'DarkRed'
                             $ButtonApplyNow.Location = '285, 20' #24,20 by default
                             $ButtonApplyNow.Name = 'ButtonApplyNow'
                             $ButtonApplyNow.Size = '125, 45'
                             $ButtonApplyNow.TabIndex = 6
                             $ButtonApplyNow.Text = $TextButton
                    $ButtonApplyNow.FlatStyle = "System"
                    $ButtonApplyNow.BackColor = '#FFFFFF'
                             #$ButtonApplyNow.UseVisualStyleBackColor = $True
                #endregion Button

                             #endregion Generated Form Code
                             #Save the initial state of the form
                             $InitialFormWindowState = $MainForm.WindowState
                             #Init the OnLoad event to correct the initial state of the form
                             #Clean up the control events
                             #Store the control values when form is closing
                             #Show the Form
                             return $MainForm.ShowDialog()


               End {
                              Write-FunctionHeaderOrFooter -CmdletName ${CmdletName} -Footer


#To launch the popup

The custom popup does not look different with or without PSADT.
Try on another PC.

You are, however, using variables with the same name as PSADT: $InitialFormWindowState, $NotifyIcon, $panelButton to name a few. Maybe PSADT changes one or more of your variables.
OR PSADT sets global setting that breaks your popup. A debugger with a breakpoint set before your function end would give you the ability to see what your variables are set to before your function terminates.

Sorry I cannot help you more.

Why you don’t use the toolkit Show-DialogBox function?
Or you can even use Show-InstallationWelcome with a -CustomText parameter which can be added in the AppDeployToolkitConfig.xml file?

1 Like

I tried to rename the variables, but it’s the same behavior.
I tried the psapp with the popup on different VM and 2 computers but it the same result each time.

I tried the show-dialogbox function but i need more customisation, that’s why i recreate one.
To add banner, and specific button (also red specific text for certain cases)

Try to reduce the size of your function to the smallest possible that still causes your problem.
This might help you to locate your issue.

Also try to run with and without PS editors. (disclaimer - I still use PowerGUI)

I tried, but it’s always the same results.
If i execute only the form directly from Powershell_ISE, i have the good size.
But if i run either the deploy-application.ps1 or the deploy-application.exe from powershell.exe or cmd.exe, i haven’t the good size at the start.
When the popup appears, i have a window, but if i click on “update now” button, the windows size’s change and become the size attended.
But if the user says “No”, he will revert to the old popup, so i want to fix it.