File Properties Dialog box using VB.Net
While working with my WPF project, I come to a requirement, where I need to display the File Properties dialog box, which available on right click on a File > selecting Properties. I got one solution from Google groups, but I forgot the link.
I am posting the code.
Imports System
Imports System.Runtime.InteropServices
Namespace Win32
<StructLayout(LayoutKind.Sequential)gt; _
Public Class SHELLEXECUTEINFO
Public cbSize As Integer
Public fMask As Integer
Public hwnd As IntPtr
Public lpVerb As String
Public lpFile As String
Public lpParameters As String
Public lpDirectory As String
Public nShow As Integer
Public hInstApp As Integer
Public lpIDList As Integer
Public lpClass As String
Public hkeyClass As Integer
Public dwHotKey As Integer
Public hIcon As Integer
Public hProcess As Integer
End Class
Public Class Shell
Public Const SEE_MASK_INVOKEIDLIST As Integer = 12
<DllImport("shell32.dll")gt; _
Public Shared Function ShellExecuteEx(<[In](), Out()> _
ByVal execInfo As SHELLEXECUTEINFO) As Boolean
End Function
End Class
End Namespace
And you can call the function like this
Dim fileInfo As New Win32.SHELLEXECUTEINFO
fileInfo.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(fileInfo)
fileInfo.lpVerb = "properties"
fileInfo.fMask = Win32.Shell.SEE_MASK_INVOKEIDLIST
fileInfo.nShow = 1
fileInfo.lpFile = filename 'File name to display properties.
Win32.Shell.ShellExecuteEx(fileInfo)
There is one issue I am facing right now with the code, the Dialog is not displayed as Modal window. I have to do R&D on it, and will update later.
Categories: .Net, .Net 3.0 / 3.5, WPF, Win 32 API

I get an “Attempted to read or write protected memory…” exception when I call ShellExecuteEx(). Any idea how to get around that?
Normally we are getting this error when the signature of the API is different.