FolderBrowserModernDialog not working in compiled .exe

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
tirwin@iot.in.gov
Posts: 40
Joined: Mon Oct 19, 2015 5:45 am

FolderBrowserModernDialog not working in compiled .exe

Post by tirwin@iot.in.gov » Fri Jan 15, 2016 6:18 am

Below is the code example, although I have similar code in other places in my app. The FolderBrowserModernDialog works fine in development or the ISE but when I compile it to an .exe and run as Administrator the FolderBrowserModernDialog freezes the app .ie (Not Responding). Why would this be happening?
Thanks
. \\iotsdsp01pw\installs$\MoveToOU\PcDeployment\Profile.ps1

$BackupForm_Load = {
		$progressbaroverlay1.Visible = $true
		$progressbaroverlay1.Maximum = 80
		$progressbaroverlay1.Step = 10
		$progressbaroverlay1.Value = 10
	
	#Initialize variables
	$wack = '\'
	$USMTBackups = 'USMTBackups'
	$dateTime = Get-Date -Format G
	$computerName = $env:computername
	$userName = (Get-WmiObject -Class Win32_ComputerSystem -Property UserName).UserName
	
		$progressbaroverlay1.PerformStep()
		$progressbaroverlay1.PerformStep()
		$progressbaroverlay1.PerformStep()
	
	$distinguishedName = (Get-dn computer cn $computerName)
	$computerObject = (Get-ADObject ($distinguishedName))
	
	$lblComputerNameBackup.Text = $computerName
	
		$progressbaroverlay1.PerformStep()
		$progressbaroverlay1.PerformStep()
		$progressbaroverlay1.PerformStep()
		$progressbaroverlay1.PerformStep()
	
	$lblUserNameBackup.Text = $userName
	$lblPhysicalLocationBackup.Text = $computerObject.location
	
		$progressbaroverlay1.PerformStep()
		$progressbaroverlay1.PerformStep()
		$progressbaroverlay1.PerformStep()
	
	$rdoGroup.Visible = $false
	$rdoTera1.Visible = $false
	$rdoTera2.Visible = $false
	$rdoTera3.Visible = $false
	$rdoTera4.Visible = $false
	$rdoTera5.Visible = $false
	$rdoTera6.Visible = $false
	$rdoTera7.Visible = $false
	$txtPath.Visible = $false
	$btnBrowse.Visible = $false
		
		Start-Sleep -s 1
		
		$progressbaroverlay1.Visible = $false
}

function Load-ComboBox 
{

	Param (
		[ValidateNotNull()]
		[Parameter(Mandatory=$true)]
		[System.Windows.Forms.ComboBox]$ComboBox,
		[ValidateNotNull()]
		[Parameter(Mandatory=$true)]
		$Items,
	    [Parameter(Mandatory=$false)]
		[string]$DisplayMember,
		[switch]$Append
	)
	
	if(-not $Append)
	{
		$ComboBox.Items.Clear()	
	}
	
	if($Items -is [Object[]])
	{
		$ComboBox.Items.AddRange($Items)
	}
	elseif ($Items -is [Array])
	{
		$ComboBox.BeginUpdate()
		foreach($obj in $Items)
		{
			$ComboBox.Items.Add($obj)	
		}
		$ComboBox.EndUpdate()
	}
	else
	{
		$ComboBox.Items.Add($Items)	
	}

	$ComboBox.DisplayMember = $DisplayMember
}

$checkboxTeraBackup_CheckedChanged={
	#TODO: Place custom script here
	if ($checkboxTeraBackup.Checked -eq $true)
	{
		$checkboxLocalBackup.Enabled = $false
		$rdoGroup.Visible = $true
		$rdoTera1.Checked = $false
		$rdoTera1.Visible = $true
		$rdoTera2.Checked = $false
		$rdoTera2.Visible = $true
		$rdoTera3.Checked = $false
		$rdoTera3.Visible = $true
		$rdoTera4.Checked = $false
		$rdoTera4.Visible = $true
		$rdoTera5.Checked = $false
		$rdoTera5.Visible = $true
		$rdoTera6.Checked = $false
		$rdoTera6.Visible = $true
		$rdoTera1.Checked = $false
		$rdoTera7.Visible = $true
		$txtPath.Text = ''
		$txtPath.Visible = $false
	}
	
	if ($checkboxTeraBackup.Checked -eq $false)
	{
		$checkboxLocalBackup.Enabled = $true
		$rdoGroup.Visible = $false
		$rdoTera1.Visible = $false
		$rdoTera2.Visible = $false
		$rdoTera3.Visible = $false
		$rdoTera4.Visible = $false
		$rdoTera5.Visible = $false
		$rdoTera6.Visible = $false
		$rdoTera7.Visible = $false
		$txtPath.Text = ''
		$txtPath.Visible = $false
	}
}

$radiobutton_CheckedChanged = {
	#Use the $this variable to access the calling control
	if ($this.Checked -eq $true)
	{
		$tera = $this.Text
		$txtPath.Visible = $true
		$txtPath.Text = $wack + $wack + $tera + $wack + $USMTBackups
	}
}

$checkboxLocalBackup_CheckedChanged = {
	
	if ($checkboxLocalBackup.Checked -eq $true)
	{
		$checkboxTeraBackup.Enabled = $false
		$rdoGroup.Visible = $false
		$rdoTera1.Visible = $false
		$rdoTera2.Visible = $false
		$rdoTera3.Visible = $false
		$rdoTera4.Visible = $false
		$rdoTera5.Visible = $false
		$rdoTera6.Visible = $false
		$rdoTera7.Visible = $false
		$txtPath.Text = ''
		$txtPath.Visible = $true
		$btnBrowse.Visible = $true
	}
	
	if ($checkboxLocalBackup.Checked -eq $false)
	{
		$checkboxTeraBackup.Enabled = $true
		$rdoGroup.Visible = $false
		$rdoTera1.Visible = $false
		$rdoTera2.Visible = $false
		$rdoTera3.Visible = $false
		$rdoTera4.Visible = $false
		$rdoTera5.Visible = $false
		$rdoTera6.Visible = $false
		$rdoTera7.Visible = $false
		$txtPath.Text = ''
		$txtPath.Visible = $false
		$btnBrowse.Visible = $false
	}
}

$btnBrowse_Click={
	if ($folderbrowsermoderndialog1.ShowDialog() -eq 'OK')
	{
		$txtPath.Text = $folderbrowsermoderndialog1.SelectedPath
	}
}

$btnSubmit_Click = {
	
	$altBackupLocation = $txtPath.Text
	
	try
	{
		if ($altBackupLocation.Length -eq 0)
		{
			$A = Start-Process -FilePath \\iotsdsp01pw\installs$\USMTWin10\dependencies\RUN-SCANSTATE.bat \\iotnasp01pw\usmtbackups$ -Wait -passthru; $a.ExitCode
		}
		else
		{
			$A = Start-Process -FilePath \\iotsdsp01pw\installs$\USMTWin10\dependencies\RUN-SCANSTATE.bat $altBackupLocation -Wait -passthru; $a.ExitCode
		}
		
		$BackupForm.Close()
		[Environment]::Exit(1)
	}
	catch
	{
		$labelDialogRedBackup.Text = “AD computer object not found”
	}
}

User avatar
dan.potter
Posts: 709
Joined: Wed Oct 08, 2014 6:02 am

Re: FolderBrowserModernDialog not working in compiled .exe

Post by dan.potter » Fri Jan 15, 2016 7:11 am

I'm just going to take a wild guess, maybe the $ in the filepath is causing the hiccup?

Sidenote, if you put your controls on panels you can hide all at one time and get rid of the redundant code.

User avatar
tirwin@iot.in.gov
Posts: 40
Joined: Mon Oct 19, 2015 5:45 am

Re: FolderBrowserModernDialog not working in compiled .exe

Post by tirwin@iot.in.gov » Fri Jan 15, 2016 8:12 am

I will take your suggestion on the panels that makes sense. But the $ in the file path works fine and is in another code path. In fact the file dialog is so the user can choose an alternate path.

User avatar
dan.potter
Posts: 709
Joined: Wed Oct 08, 2014 6:02 am

Re: FolderBrowserModernDialog not working in compiled .exe

Post by dan.potter » Fri Jan 15, 2016 8:34 am

does this freeze?
browse.zip
(93.59 KiB) Downloaded 86 times

User avatar
tirwin@iot.in.gov
Posts: 40
Joined: Mon Oct 19, 2015 5:45 am

Re: FolderBrowserModernDialog not working in compiled .exe

Post by tirwin@iot.in.gov » Fri Jan 15, 2016 8:45 am

No sir, when I right click > run as Administrator with my elevated account I get the following screen shot. I does nothing with my unelevated account.
Browse.PNG
Browse.PNG (49.24 KiB) Viewed 2000 times

User avatar
dan.potter
Posts: 709
Joined: Wed Oct 08, 2014 6:02 am

Re: FolderBrowserModernDialog not working in compiled .exe

Post by dan.potter » Fri Jan 15, 2016 9:10 am

try it on another system? That's completely stripped down to a textbox, button and browse dialogue.

User avatar
tirwin@iot.in.gov
Posts: 40
Joined: Mon Oct 19, 2015 5:45 am

Re: FolderBrowserModernDialog not working in compiled .exe

Post by tirwin@iot.in.gov » Fri Jan 15, 2016 9:20 am

I tried putting it on another server but it still does not open Sir.

User avatar
davidc
Posts: 5913
Joined: Thu Aug 18, 2011 4:56 am

Re: FolderBrowserModernDialog not working in compiled .exe

Post by davidc » Fri Jan 15, 2016 9:56 am

All the file and folder dialogs require STA mode to function correctly. Please make sure you check the STA option in your packager settings otherwise the dialog will not appear.
Packager STA Option.png
Packager STA Option.png (53.5 KiB) Viewed 1987 times
David
David
SAPIEN Technologies, Inc.

User avatar
tirwin@iot.in.gov
Posts: 40
Joined: Mon Oct 19, 2015 5:45 am

Re: FolderBrowserModernDialog not working in compiled .exe

Post by tirwin@iot.in.gov » Fri Jan 15, 2016 11:03 am

That sounds like a good solution but is still does not work. Now when I check the box the way you did and click ok the engine goes away and when I click setting again it always comes back unchecked? see two screen shots.
screen1.PNG
screen1.PNG (52.71 KiB) Viewed 1985 times
screen1.PNG
screen1.PNG (52.71 KiB) Viewed 1985 times
Attachments
screen2.PNG
screen2.PNG (50.27 KiB) Viewed 1985 times

User avatar
tirwin@iot.in.gov
Posts: 40
Joined: Mon Oct 19, 2015 5:45 am

Re: FolderBrowserModernDialog not working in compiled .exe

Post by tirwin@iot.in.gov » Fri Jan 15, 2016 11:05 am

sorry I posted screen1 twice.

Locked