1

I am trying to build an application similar to the Windows File Explorer, in VB.net. I want do use the the same window that is displayed when right clicking a file in the File Explorer, clicking Properties in the meny. The thing is, this is very easy to solve, but it only works if my application is compiled as a 32-bit application, when I compile it as 64-bit, this doesn't work.

There are two kinds of answer that I would like:

  1. The best would be to show this file Properties window from a 64-bit application.
  2. The second best would be to create a 32-bit application as a wrapper, that just have the purpose to show the file Properties window. I was almost able to fix this, but I do not know how to trace when the OK or Cancel button is clicked.

Here below is the code I use, that works fine in 32-bit VB.net:

  Private Declare Function ShellExecuteEX Lib "shell32.dll" Alias "ShellExecuteEx" (ByRef SEI As SHELLEXECUTEINFO) As Integer

  Private Structure SHELLEXECUTEINFO
    Dim cbSize As Integer
    Dim fMask As Integer
    Dim hwnd As Integer
    Dim lpVerb As String
    Dim lpFile As String
    Dim lpParameters As String
    Dim lpDirectory As String
    Dim nShow As Integer
    Dim hInstApp As Integer
    Dim lpIDList As Integer
    Dim lpClass As String
    Dim hkeyClass As Integer
    Dim dwHotKey As Integer
    Dim hIcon As Integer
    Dim hProcess As Integer
  End Structure

  Private Const SEE_MASK_INVOKEIDLIST As Short = &HCS
  Private Const SEE_MASK_NOCLOSEPROCESS As Short = &H40S
  Private Const SEE_MASK_FLAG_NO_UI As Short = &H400S
  Private Const SW_SHOWNORMAL As Integer = 1

Public Function ShowProps(ByVal FileName As String, ByVal OwnerhWnd As Integer) As Boolean
    Dim SEI As SHELLEXECUTEINFO = Nothing
    Dim r As Integer
    With SEI
      .cbSize = Len(SEI)
      .fMask = SEE_MASK_NOCLOSEPROCESS Or SEE_MASK_INVOKEIDLIST Or SEE_MASK_FLAG_NO_UI
      .hwnd = OwnerhWnd
      .lpVerb = "properties"
      .lpFile = FileName
      .lpParameters = vbNullChar
      .lpDirectory = vbNullChar
      .nShow = 0
      .hInstApp = 0
      .lpIDList = 0
    End With
    r = ShellExecuteEX(SEI)
    If r <= 0 Then
      Return False
    End If

    Return True
  End Function
  • You might consider using `Process.Start` as described [here](https://stackoverflow.com/a/1936784/111794). – Zev Spitz Feb 22 '21 at 02:29
  • See the example for displaying the property window on pinvoke.net for [ShellExecuteEx](http://pinvoke.net/default.aspx/shell32/ShellExecuteEx.html) near the bottom of the page. Also note the usage of `IntPtr` for the handle fields in SHELLEXECUTEINFO. – TnTinMn Feb 22 '21 at 03:35
  • Have a look at this: https://stackoverflow.com/a/27696310/553663 – J. Scott Elblein Feb 22 '21 at 20:32

0 Answers0