0

In my WPF application I am using ShellExecuteEx to show the properties window of a shortcut (.lnk file):

    [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 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 bool 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;
        return ShellExecuteEx(ref info);
    }

When I compare the properties window shown by my application with the one from the windows context menu, the "Target" field is different:

enter image description here

I suspect it has something to do with the app being x64 but not sure how to fix this.

Ross Patterson
  • 257
  • 1
  • 3
  • 10
  • 4
    You should just make sure your app is compiled for x64 on a x64 OS, i.e.: uncheck prefer 32-bit https://stackoverflow.com/questions/12066638/what-is-the-purpose-of-the-prefer-32-bit-setting-in-visual-studio-and-how-does and select platform target as "Any Cpu" – Simon Mourier Mar 02 '22 at 10:18
  • 1
    Is it remotely possible that these are different shortcuts? – David Heffernan Mar 02 '22 at 14:21
  • 1
    The fact that different icons and targets are displayed pretty much guarantees that different links are being accessed. What is the actual value of `fileName`? Does it contain a path that is virtualized for 32bit processes? Also, look on the General tab of the properties dialog, it should show the path if the actual file whose properties are being accessed. – Remy Lebeau Mar 02 '22 at 15:25
  • Perhaps [the answer](https://stackoverflow.com/a/54228410/15511041) answer your question. – YangXiaoPo-MSFT Mar 03 '22 at 02:45
  • 1
    @SimonMourier Thank you! I unchecked "Prefer 32 Bit" from the Build section in Properties and now the icon and target is showing correctly. – Ross Patterson Mar 03 '22 at 08:57

0 Answers0