-
Notifications
You must be signed in to change notification settings - Fork 7
/
FileAssoc.cs
58 lines (51 loc) · 1.29 KB
/
FileAssoc.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
using System;
using System.Text;
using System.Runtime.InteropServices;
namespace Hosts;
internal static class FileAssoc
{
[DllImport("shlwapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern uint AssocQueryString(AssocF flags, AssocStr str, string pszAssoc, string pszExtra, [Out] StringBuilder sOut, [In][Out] ref uint nOut);
[Flags]
public enum AssocF
{
Init_NoRemapCLSID = 0x1,
Init_ByExeName = 0x2,
Open_ByExeName = 0x2,
Init_DefaultToStar = 0x4,
Init_DefaultToFolder = 0x8,
NoUserSettings = 0x10,
NoTruncate = 0x20,
Verify = 0x40,
RemapRunDll = 0x80,
NoFixUps = 0x100,
IgnoreBaseClass = 0x200
}
enum AssocStr
{
Command = 1,
Executable,
FriendlyDocName,
FriendlyAppName,
NoOpen,
ShellNewValue,
DDECommand,
DDEIfExec,
DDEApplication,
DDETopic
}
public static string GetExecutable(string doctype)
{
uint out_path_size = 0;
if (AssocQueryString(AssocF.Verify, AssocStr.Executable, doctype, null, null, ref out_path_size) != 1)
{
return null;
}
StringBuilder out_path = new StringBuilder((int)out_path_size);
if (AssocQueryString(AssocF.Verify, AssocStr.Executable, doctype, null, out_path, ref out_path_size) != 0)
{
return null;
}
return out_path.ToString();
}
}