我试图打开文件的信息属性。
在以前版本的Windows中,显示了属性窗口,然后在我的代码中将控件提供给下一个函数,但在Windows 10中,函数调用卡住了,直到我通过鼠标单击关闭文件属性。
我想知道新的Windows版本有哪些改变?
我的代码如下:
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.");
}