VB.net: Showing the File Properties window from a 64-bit application?

  64-bit, explorer, shellexecuteex, vb.net, windows

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

Source: Windows Questions

LEAVE A COMMENT