1. Herfried K. Wagner’s VB.Any
  2. .NET
  3. Frequently Asked Questions

Displaying the “Open with...” dialog

Displaying the "Open with..."dialog
<URL:https://dotnet.currifex.org/dotnet/faqs/openwithdialog/en/>
----------------------------------------------------------------------------

Displaying the "Open with..." dialog

When using 'Process.Start' to open a file with its associated application,
an exception will be thrown if there is no program associated with the file
type.  One way to show the system's "Open With..." dialog box is to catch
this exception and use an undocumented function via p/invoke:

\\\
Imports System.Runtime.InteropServices
.
.
.
Private Declare Auto Function OpenWithDialog _
    Lib "shell32.dll" _
    Alias "OpenAs_RunDLL" _
( _
    ByVal hwnd As IntPtr, _
    ByVal hinst As IntPtr, _
    ByVal lpFile As String, _
    ByVal nShowCmd As Int32 _
) As Int32
.
.
.
OpenWithDialog( _
    Me.Handle, _
    Marshal.GetHINSTANCE(Me.GetType().Module), _
    "C:\AUTOEXEC.BAT", _
    CInt(AppWinStyle.NormalFocus) _
)
///

Alternatively (that is the preferred way because it is fully managed) this
solution can be used:

\\\
Imports System.Diagnostics
.
.
.
Dim psi As New ProcessStartInfo()
psi.ErrorDialog = True
psi.FileName = "C:\AUDOEXEC.BAT"
psi.UseShellExecute = True
Process.Start(psi)
///