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.
This topic is 8 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
tirwin@iot.in.gov
Posts: 40
Last visit: Tue Mar 14, 2017 9:54 am

FolderBrowserModernDialog not working in compiled .exe

Post by tirwin@iot.in.gov »

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
Last visit: Wed Nov 14, 2018 11:39 am

Re: FolderBrowserModernDialog not working in compiled .exe

Post by dan.potter »

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
Last visit: Tue Mar 14, 2017 9:54 am

Re: FolderBrowserModernDialog not working in compiled .exe

Post by tirwin@iot.in.gov »

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
Last visit: Wed Nov 14, 2018 11:39 am

Re: FolderBrowserModernDialog not working in compiled .exe

Post by dan.potter »

does this freeze?
browse.zip
(93.59 KiB) Downloaded 166 times
User avatar
tirwin@iot.in.gov
Posts: 40
Last visit: Tue Mar 14, 2017 9:54 am

Re: FolderBrowserModernDialog not working in compiled .exe

Post by tirwin@iot.in.gov »

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 3509 times
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: FolderBrowserModernDialog not working in compiled .exe

Post by dan.potter »

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
Last visit: Tue Mar 14, 2017 9:54 am

Re: FolderBrowserModernDialog not working in compiled .exe

Post by tirwin@iot.in.gov »

I tried putting it on another server but it still does not open Sir.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: FolderBrowserModernDialog not working in compiled .exe

Post by davidc »

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 3496 times
David
David
SAPIEN Technologies, Inc.
User avatar
tirwin@iot.in.gov
Posts: 40
Last visit: Tue Mar 14, 2017 9:54 am

Re: FolderBrowserModernDialog not working in compiled .exe

Post by tirwin@iot.in.gov »

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 3494 times
screen1.PNG
screen1.PNG (52.71 KiB) Viewed 3494 times
Attachments
screen2.PNG
screen2.PNG (50.27 KiB) Viewed 3494 times
User avatar
tirwin@iot.in.gov
Posts: 40
Last visit: Tue Mar 14, 2017 9:54 am

Re: FolderBrowserModernDialog not working in compiled .exe

Post by tirwin@iot.in.gov »

sorry I posted screen1 twice.
This topic is 8 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked