PowerShell GUIs - File Dialog Hanging
- Written by David Corrales
- Last Updated: 14 November 2017
- Created: 26 February 2009
- Hits: 5452
Some users may find that their script hangs when using a OpenFileDialog or SaveFileDialog.
The bad news is that scripts which include OpenFileDialogs or SaveFileDialogs and that previously worked on Windows XP may encounter freezing issues on Vista SP1 systems with .Net 3.0/3.5. The affected scripts will hang when PowerShell executes the File Dialog’s ShowDialog function. It’s important to note that this issue is not limited to PowerShell but may affect any other .Net application.
The good news is that there is a work-around for this issue. In order to prevent this problem, you must set the dialog’s ShowHelp property to $True before calling the ShowDialog function. If you are using SaveFileDialog you will also want to set the CreatePrompt and OverwritePrompt properties to $True as well.
$saveFileDialog1 = New-Object System.Windows.Forms.SaveFileDialog $saveFileDialog1.ShowHelp = $True $saveFileDialog1.OverwritePrompt = $True $saveFileDialog1.CreatePrompt = $True $saveFileDIalog1.ShowDialog() #It is now safe to call this function