ShellExecuteEx function works in a different way in Windows 10?

826 views Asked by At

I'm trying to open info property of file. In the previous versions of Windows, properties window was shown and then the control was given to next function in my code, but in Windows 10 function call stucks until I'm closing file properties with mouse click.
I wonder what have been changed in the new Windows version?
My code is below:

  private const int SwShow = 5;
    private const uint SeeMaskInvokeidlist = 12;

    public static bool ShowFileProperties(string filename)
    {
        var info = new Shellexecuteinfo();
        info.cbSize = Marshal.SizeOf(info);
        info.lpVerb = "properties";
        info.lpFile = filename;
        info.nShow = SwShow;
        info.fMask = SeeMaskInvokeidlist;
        return ShellExecuteEx(ref info);
    }

    [DllImport("shell32.dll", CharSet = CharSet.Auto)]
    private 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;
    }

    static void Main(string[] args)
    {
        Console.WriteLine("Show file info.");

        ShowFileProperties(args[0]);

        Thread.Sleep(TimeSpan.FromSeconds(2));

        Console.WriteLine("File info was shown.");


    }
0

There are 0 answers