Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

SHObjectProperties (shell32)
 
.
Summary
(from MSDN) Invokes the Properties context menu command on a Shell object.

Sample Code:

C#

    using System;  
    using System.Collections.Generic;
    using System.Runtime.InteropServices;

    public class Program
    {
    [DllImport("shell32.dll", SetLastError=true)]
    static extern bool SHObjectProperties(UInt32 hwnd, UInt32 shopObjectType, [MarshalAs(UnmanagedType.LPWStr)] string pszObjectName, [MarshalAs(UnmanagedType.LPWStr)] string pszPropertyPage);
        public static void Main()
        {
            SHObjectProperties(0,2,"C:\\Windows",null);
            Console.ReadKey();
        }
    }

C# Signature:

[DllImport("shell32.dll", SetLastError=true)]
static extern bool SHObjectProperties(uint32 hwnd, uint32 shopObjectType, [MarshalAs(UnmanagedType.LPWStr)] string pszObjectName, [MarshalAs(UnmanagedType.LPWStr)] string pszPropertyPage);

(not 100% certain this is correct, need to test)

VB Signature:

Declare Function SHObjectProperties Lib "shell32.dll" _
    (ByVal hwnd As UInt32, ByVal shopObjectType As UInt32, _
    <MarshalAs(UnmanagedType.LPWStr)> ByVal pszObjectName As String, _
    <MarshalAs(UnmanagedType.LPWStr)> ByVal pszPropertyPage As String) As Boolean

User-Defined Types:

Optional Enum used to set shopObjectType for pszObjectName:

    Public Enum GetProperties
    SHOP_PRINTERNAME = &H1  '// lpObject points to a printer friendly name
    SHOP_FILEPATH = &H2  '// lpObject points to a fully qualified path+file name
    SHOP_VOLUMEGUID = &H4  '// lpObject points to a Volume GUID
    End Enum

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

Took me forever (okay, less than an hour) to figure out that this function failed with Integers or Longs and it wanted UInt32 for hwnd and shopObjectType.

Tips & Tricks:

Please add some!

Sample Code:

VB

    Sub Main()
    ShowProp("C:\boot.ini")
    'needed to keep the properties window open (window is bound to current application handle)
    Console.ReadKey()
    End Sub


    Public Enum GetProperties
    SHOP_PRINTERNAME = &H1  '// lpObject points to a printer friendly name
    SHOP_FILEPATH = &H2  '// lpObject points to a fully qualified path+file name
    SHOP_VOLUMEGUID = &H4  '// lpObject points to a Volume GUID
    End Enum

    Private Declare Function SHObjectProperties Lib "shell32.dll" _
    (ByVal hwnd As UInt32, ByVal shopObjectType As UInt32, _
    <MarshalAs(UnmanagedType.LPWStr)> ByVal pszObjectName As String, _
    <MarshalAs(UnmanagedType.LPWStr)> ByVal pszPropertyPage As String) As Boolean

    Public Function ShowProp(ByVal filename As String, Optional ByVal page As String = "") As Boolean
    If page = String.Empty Then
        page = 0
    Else
        page = page
    End If
    ShowProp = SHObjectProperties(0, GetProperties.SHOP_FILEPATH, filename, String.Empty)
    End Function


Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions