Powershell OpenFileDialog is not showing up

Recently I was writing scripts that should run on a Windows 7 machine. One task was to select a file and read it. So I used the usual snippet:

$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
[void]$OpenFileDialog.ShowDialog()

I ran the script from PowerShell ISE during development and everything worked fine but when the users executed the script, the file dialog did not open up. Then I came across this page here and it said ShowHelp solves the problem. I changed the script to:

$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.ShowHelp = $true
[void]$OpenFileDialog.ShowDialog()

I am not sure why, but this solved the problem and did not cause any other side effect. I am wondering what ShowHelp actual does because it seems to have no visible effect.

Advertisements

One thought on “Powershell OpenFileDialog is not showing up

  1. Danke,
    $OpenFileDialog.ShowHelp = $true

    Hat mir geholfen, einen openfiledialog aus einer Winform(Primalforms) heraus unter W10 mit ps2exe compilierten Powershell zur Anzeige zu bringen.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s