C# Example of Property Dialog

Just added to http://pinvoke.net

http://pinvoke.net/default.aspx/shell32/ShellExecuteEx.html

Using ShellExecuteEx to show the properties dialog box of a file.

public static void ShowFileProperties(string Filename) {
    SHELLEXECUTEINFO info = new SHELLEXECUTEINFO();
    info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info);
    info.lpVerb = "properties";
    info.lpFile = Filename;
    info.nShow = SW_SHOW;
    info.fMask = SEE_MASK_INVOKEIDLIST;
    ShellExecuteEx(ref info);
}

private const int SW_SHOW = 5;
private const uint SEE_MASK_INVOKEIDLIST = 12;

[DllImport("shell32.dll")]
static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo);

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]

    public struct SHELLEXECUTEINFO
    {
        public int cbSize;
        public uint fMask;
        public IntPtr hwnd;
        public String lpVerb;
        public String lpFile;
        public String lpParameters;
        public String lpDirectory;
        public int nShow;
        public int hInstApp;
        public int lpIDList;
        public String lpClass;
        public int hkeyClass;
        public uint dwHotKey;
        public int hIcon;
        public int hProcess;
    }

 

7 Comments

  • alexch said

    The SHELLEXECUTEINFO presented is valid only for Win32 (some "int" must be "IntPtr"); it should look like: [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct SHELLEXECUTEINFO { public int cbSize; public uint fMask; public IntPtr hwnd; public String lpVerb; public String lpFile; public String lpParameters; public String lpDirectory; public int nShow; public IntPtr hInstApp; public IntPtr lpIDList; public String lpClass; public IntPtr hkeyClass; public uint dwHotKey; public IntPtr hIcon; public IntPtr hProcess; }

  • Harish said

    Using SHELLEXECUTEINFO i am opening an application. How do i make the SHELLEXECUTEINFO make wait till the child application is closed?

Comments have been disabled for this content.