none
Checkbox issue when calling OpenWith from vb.net RRS feed

  • Question

  • I have a problem when calling OpenWith from vb.net. When the OpenWith dialog box shows, the checkbox for "Always use this program" is missing. Other than that, the dialog boxes look the same. I'm using Windows 10 version 1909 and Visual Studio 2019 version 16.4.0. I've talked to another developer about this and he says he can run:
    RUNDLL32.EXE shell32.dll OpenAs_RunDLL c:\users\eggba\desktop\deskview.png from the command line and the checkbox shows up. However when I try it, there is no checkbox. 

    Below is the last code I've tried. I've been trying to get this to work for days now, so any help at all would be appreciated!

        Public Enum OPEN_AS_INFO_FLAGS
            OAIF_ALLOW_REGISTRATION = &H1 'enable the "always use this file" checkbox (NOTE If you don't pass this, it will be disabled)
            OAIF_REGISTER_EXT = &H2 'Do the registration after the user hits "ok"
            OAIF_EXEC = &H4 ' execute file after registering
            OAIF_FORCE_REGISTRATION = &H8 'force the "always use this file" checkbox To be checked (normally, you won't use the OAIF_ALLOW_REGISTRATION when you pass this)
            OAIF_HIDE_REGISTRATION = &H20 'hide the "always use this file" checkbox
            OAIF_URL_PROTOCOL = &H40 'the "extension" passed Is actually a protocol (uri scheme), And open With should show apps registered As capable Of handling that protocol
            OAIF_FILE_IS_URI = &H80 'pcszFile Is actually a URI
        End Enum
    
        <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
        Public Structure OPENASINFO
            <MarshalAs(UnmanagedType.LPWStr)>
            Dim strName As String
            <MarshalAs(UnmanagedType.LPWStr)>
            Dim strClass As String
            <MarshalAs(UnmanagedType.I4)>
            Dim oainfo As OPEN_AS_INFO_FLAGS
        End Structure
    
        <DllImport("Shell32.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Unicode, PreserveSig:=False)>
        Public Shared Sub SHOpenWithDialog(ByVal hwnd As IntPtr, ByRef openasinfo As OPENASINFO)
        End Sub
    
        Private Sub MyOpenWith_click() Handles MyOpenWith.Click
            Dim LviewText As String = Path.Combine(DeskTopPath, ListView1.SelectedItems(0).Tag)
            If isLink(LviewText) Then
                LviewText = ResolveShortcut(LviewText)
            End If
    
            Dim oif As New OPENASINFO
    
            oif.strName = LviewText
            oif.strClass = vbNullString
            oif.oainfo = OPEN_AS_INFO_FLAGS.OAIF_ALLOW_REGISTRATION Or OPEN_AS_INFO_FLAGS.OAIF_EXEC
    
            Dim tmp As String = Path.GetExtension(LviewText)
            Try
                If tmp = ".lnk" Then ' Check to see if it's a shortcut, then get the actual location
                    LviewText = ResolveShortcut(LviewText)
                    oif.strName = LviewText ' if it's a link, need to store the real path in oif.strName after being resolved
    
                    If File.Exists(LviewText) Then
                        SHOpenWithDialog(Handle, oif)
                    Else
                        SHOpenWithDialog(Handle, oif)
                    End If
                Else
                    Try
                        SHOpenWithDialog(Handle, oif)
                    Catch ex As Exception
                        'MsgBox(ex.Message)
                    End Try
                End If
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
    
        End Sub

    Sunday, December 8, 2019 8:11 AM

Answers

  • Note that OAIF_ALLOW_REGISTRATION is ignored, according to documentation.


    • Edited by Viorel_MVP Sunday, December 8, 2019 10:00 AM
    • Marked as answer by eggbath77 Sunday, December 8, 2019 1:13 PM
    Sunday, December 8, 2019 9:59 AM

All replies

  • Note that OAIF_ALLOW_REGISTRATION is ignored, according to documentation.


    • Edited by Viorel_MVP Sunday, December 8, 2019 10:00 AM
    • Marked as answer by eggbath77 Sunday, December 8, 2019 1:13 PM
    Sunday, December 8, 2019 9:59 AM
  • Thank you for the reply. I haven't read that in the docs. I've tried a lot of code to solve the issue, but the only way I can ever see the checkbox is to right click on a file in explorer and select "OpenWith". I'm beginning to wonder if it's a Windows 10 issue? I would be happy to find any solution for this, like an external application I can pass file names to or an "OpenWith" control.

    Right now I can't think of anything else to search for on the net. 

    Sunday, December 8, 2019 12:31 PM
  •  I would be happy to find any solution for this

    You marked the thread as answered, so no one will answer anymore...
    Sunday, December 8, 2019 7:52 PM