1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
[StructLayout(LayoutKind.Sequential)]
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;
}
....
private const int SW_SHOW = 5;
private const uint SEE_MASK_INVOKEIDLIST = 12;
[DllImport("shell32.dll")]
static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo);
public static void ShowProperties(string path)
{
FileInfo fi = new FileInfo(path);
SHELLEXECUTEINFO info = new SHELLEXECUTEINFO();
info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info);
info.lpVerb = "properties";
info.lpFile = fi.Name;
info.lpDirectory = fi.DirectoryName;
info.nShow = SW_SHOW;
info.fMask = SEE_MASK_INVOKEIDLIST;
ShellExecuteEx(ref info);
}
// Beispielaufruf:
// die Eingenschaften des Verzeichnisses "c:\temp" anzeigen
ShowProperties(@"c:\temp");
// die Eingenschaften der Datei "c:\temp\test.bmp" anzeigen
ShowProperties(@"c:\temp\test.bmp");
|