Page 1 of 4

FolderBrowserModernDialog not working in compiled .exe

Posted: Fri Jan 15, 2016 6:18 am
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”
	}
}

Re: FolderBrowserModernDialog not working in compiled .exe

Posted: Fri Jan 15, 2016 7:11 am
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.

Re: FolderBrowserModernDialog not working in compiled .exe

Posted: Fri Jan 15, 2016 8:12 am
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.

Re: FolderBrowserModernDialog not working in compiled .exe

Posted: Fri Jan 15, 2016 8:34 am
by dan.potter
does this freeze?
browse.zip
(93.59 KiB) Downloaded 93 times

Re: FolderBrowserModernDialog not working in compiled .exe

Posted: Fri Jan 15, 2016 8:45 am
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 2141 times

Re: FolderBrowserModernDialog not working in compiled .exe

Posted: Fri Jan 15, 2016 9:10 am
by dan.potter
try it on another system? That's completely stripped down to a textbox, button and browse dialogue.

Re: FolderBrowserModernDialog not working in compiled .exe

Posted: Fri Jan 15, 2016 9:20 am
by tirwin@iot.in.gov
I tried putting it on another server but it still does not open Sir.

Re: FolderBrowserModernDialog not working in compiled .exe

Posted: Fri Jan 15, 2016 9:56 am
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 2128 times
David

Re: FolderBrowserModernDialog not working in compiled .exe

Posted: Fri Jan 15, 2016 11:03 am
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 2126 times
screen1.PNG
screen1.PNG (52.71 KiB) Viewed 2126 times

Re: FolderBrowserModernDialog not working in compiled .exe

Posted: Fri Jan 15, 2016 11:05 am
by tirwin@iot.in.gov
sorry I posted screen1 twice.