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();
}
}
[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)
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
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
Do you know one? Please contribute it!
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.
Please add some!
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