Rob Chartier ~ Contemplation...

.NET, C#, Work, etc.

News






www.flickr.com
This is a Flickr badge showing public photos from Rob & Kat Chartier. Make your own badge here.


Even Quicker Links

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;
    }

 

Comments

Smith said:

Exactly what I was looking for.

Much appreciated.

# December 16, 2006 1:26 AM

twig said:

[DllImport("shell32.dll")]

your dll import is missing Charset = Charset.Auto

as shown in www.pinvoke.net/.../ShellExecuteEx.html

# August 27, 2008 8:20 PM

Mahesh Bagul said:

It works but I want it to show for multiple files?

Any help?

# April 27, 2009 7:01 AM

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;

}

# May 14, 2009 10:52 AM

Mikkel said:

Is there any way of making the Property window TopMost like BringToFront()?

# March 30, 2010 6:44 AM

Md. Rashim Uddin said:

How do we make it working for multiple selected file?

# April 20, 2010 2:06 AM

Harish said:

Using SHELLEXECUTEINFO i am opening an application.

How do i make the SHELLEXECUTEINFO make wait till the child application is closed?

# May 17, 2010 8:32 AM

Steph said:

Using "Charset = Charset.Auto" gives me an errormessage with chinese or whatever symbols... *lol*

# August 14, 2010 11:50 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)