Visual Basic Win32 Shell Routines
ShellExecuteEx: Displaying a File's Property Page
Posted:   Sunday April 13, 1997
Updated:   Monday December 26, 2011
Applies to:   VB4-32, VB5, VB6
Developed with:   VB4-32, Windows 95
OS restrictions:   None
Author:   VBnet - Randy Birch


ShellExecuteEx: Drive, Folder & File Property Pages

Using using this simple routine, the SHELLEXECUTEINFO type structure and the ShellExecuteEx() API, 32 bit Visual Basic applications can display the file property page for any passed file on Windows 95, 98 or NT4. As long as the path to the file is known, this routine can be invoked. It works for both registered and unregistered Windows file types, as well as bringing up the DOS property sheet for DOS applications or files (try pointing the app to autoexec.bat).

Thanks go out to Ian Land for providing the Delphi code, and Roy Meyers for sending it to me for VBnet.
 BAS Module Code

 Form Code
To a project form add two command buttons (Command1 and Command2) and a text box (Text1). Add the following to the form:

Option Explicit
' Copyright 1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
' Distribution: You can freely use this code in your own
'               applications, but you may not reproduce 
'               or publish this code on any web site,
'               online service, or distribute as source 
'               on any media without express permission.
    cbSize        As Long
    fMask         As Long
    hwnd          As Long
    lpVerb        As String
    lpFile        As String
    lpParameters  As String
    lpDirectory   As String
    nShow         As Long
    hInstApp      As Long
    lpIDList      As Long     'Optional
    lpClass       As String   'Optional
    hkeyClass     As Long     'Optional
    dwHotKey      As Long     'Optional
    hIcon         As Long     'Optional
    hProcess      As Long     'Optional
End Type

Private Const SEE_MASK_FLAG_NO_UI = &H400

Private Declare Function ShellExecuteEx Lib "shell32" _
   Alias "ShellExecuteExA" _

Private Sub Form_Load()

   Command1.Caption = "Show Properties"
  'assure string points to a valid file
  'on your system
   Text1.Text = "c:\windows\notepad.exe"
End Sub

Private Sub Command1_Click()
  'show the properties dialog, passing the filename
  'and the owner of the dialog  
   Call ShowProperties(Text1.Text, Me.hwnd) 

End Sub

Private Sub Command2_Click()
   Unload Me
End Sub

Private Sub ShowProperties(sFilename As String, hWndOwner As Long)
  'open a file properties property page for 
  'specified file if return value

  'Fill in the SHELLEXECUTEINFO structure 
   With SEI
      .cbSize = Len(SEI)
               SEE_MASK_INVOKEIDLIST Or _
      .hwnd = hWndOwner
      .lpVerb = "properties"
      .lpFile = sFilename
      .lpParameters = vbNullChar
      .lpDirectory = vbNullChar
      .nShow = 0
      .hInstApp = 0
      .lpIDList = 0
   End With
  'call the API to display the property sheet 
   Call ShellExecuteEX(SEI)
End Sub
Run the project, enter a file path and name into the textbox, and hit properties. The Windows properties page for the specified file will appear. This code displays only a single property page, even if multiple files are selected. At this time I know of no API call that displays the Explorer property page showing the file size sum from a selection of multiple files, other than passing a folder instead to retrieve the total folder size.


PayPal Link
Make payments with PayPal - it's fast, free and secure!


Copyright 1996-2011 VBnet and Randy Birch. All Rights Reserved.
Terms of Use  |  Your Privacy


Hit Counter