In XP, I was able to show the File Properties dialog from c# code. The essential bits are shown below;
This no longer works in Windows 7 64 bit. Surely it must be implemented more simply now?

I have searched the internet for a replacement method without success.

I noticed that the DllImport refers to shell32.dll, is there a replacement for Windows 7, 64 bit?

    private void ShowFileProperties(string fileName, string verbName)
    {
        SHELLEXECUTEINFO info = new SHELLEXECUTEINFO();
        info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info);
        info.lpVerb = verbName;
        info.lpFile = fileName;
        info.nShow = SW_SHOW;
        info.fMask = SEE_MASK_INVOKEIDLIST;
        ShellExecuteEx(ref info);
    }

    [DllImport("shell32.dll", CharSet = CharSet.Auto)]
    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;
        [MarshalAs(UnmanagedType.LPTStr)] 
        public String lpVerb;
        [MarshalAs(UnmanagedType.LPTStr)] 
        public String lpFile;
        [MarshalAs(UnmanagedType.LPTStr)] 
        public String lpParameters;
        [MarshalAs(UnmanagedType.LPTStr)] 
        public String lpDirectory;
        public int nShow;
        public int hInstApp;
        public int lpIDList;
        [MarshalAs(UnmanagedType.LPTStr)] 
        public String lpClass;
        public int hkeyClass;
        public uint dwHotKey;
        public int hIcon;
        public int hProcess;
    }

Thanks, but its not what I am after.

If you right click on a file in windows explorer and select 'properties', a properties dialog appears. I would like to generate that dialog from code. I was able to do this in XP. In XP, all the common windows dialogs were accessible from code such as 'print', 'colour' etc. It seems less straight forward in Windows 7.

This works fine for me using Win 7 64-bit. It has a slightly different structure definition than what you use:

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

        [StructLayout(LayoutKind.Sequential)]
        public struct SHELLEXECUTEINFO {
            public int cbSize;
            public uint fMask;
            public IntPtr hwnd;
            [MarshalAs(UnmanagedType.LPTStr)]
            public string lpVerb;
            [MarshalAs(UnmanagedType.LPTStr)]
            public string lpFile;
            [MarshalAs(UnmanagedType.LPTStr)]
            public string lpParameters;
            [MarshalAs(UnmanagedType.LPTStr)]
            public string lpDirectory;
            public int nShow;
            public IntPtr hInstApp;
            public IntPtr lpIDList;
            [MarshalAs(UnmanagedType.LPTStr)]
            public string lpClass;
            public IntPtr hkeyClass;
            public uint dwHotKey;
            public IntPtr hIcon;
            public IntPtr hProcess;
        }

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

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

Thank you Momerath. My software has burst back into life and works again as intended. Totally bizarre. The seemingly small change made all the difference. What changed between XP and Win 7 64 bit to make this change important?
Anyway problem solved, thanks again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.