-
Notifications
You must be signed in to change notification settings - Fork 5
/
CertificateDialog.cs
60 lines (55 loc) · 1.84 KB
/
CertificateDialog.cs
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
50
51
52
53
54
55
56
57
58
59
60
namespace X509CertificateTool;
using System;
using System.Runtime.InteropServices;
/// <summary>
/// P/Invoke wrapper for showing the Win32 Certificate dialog.
/// </summary>
internal class CertificateDialog
{
private CertificateDialog() { }
internal static void ShowFilePropertiesDialog(IntPtr hwnd, string directory, string file)
{
CertificateDialog.SHELLEXECUTEINFO shellexecuteinfo1 = new CertificateDialog.SHELLEXECUTEINFO
{
cbSize = Marshal.SizeOf(typeof(CertificateDialog.SHELLEXECUTEINFO)),
fMask = 12,
lpVerb = "Properties",
hwnd = hwnd,
lpParameters = null,
lpDirectory = directory,
lpFile = file,
hInstApp = IntPtr.Zero,
lpIDList = IntPtr.Zero,
hkeyClass = IntPtr.Zero,
hIcon = IntPtr.Zero,
hProcess = IntPtr.Zero
};
IntPtr ptr1 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(CertificateDialog.SHELLEXECUTEINFO)));
Marshal.StructureToPtr(shellexecuteinfo1, ptr1, false);
_ = SafeNativeMethods.ShellExecuteEx(ptr1);
Marshal.FreeHGlobal(ptr1);
}
[StructLayout(LayoutKind.Sequential)]
private class SHELLEXECUTEINFO
{
public int cbSize;
public int fMask;
public IntPtr hwnd;
[MarshalAs(UnmanagedType.LPWStr)]
public string lpVerb;
[MarshalAs(UnmanagedType.LPWStr)]
public string lpFile;
[MarshalAs(UnmanagedType.LPWStr)]
public string lpParameters;
[MarshalAs(UnmanagedType.LPWStr)]
public string lpDirectory;
public int nShow;
public IntPtr hInstApp;
public IntPtr lpIDList;
public string lpClass;
public IntPtr hkeyClass;
public int dwHotKey;
public IntPtr hIcon;
public IntPtr hProcess;
}
}