Checkbox issue when calling OpenWith from vb.net

  • Thread starter Thread starter eggbath77
  • Start date Start date
E

eggbath77

Guest
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

Continue reading...
 
Back
Top