-
Notifications
You must be signed in to change notification settings - Fork 3
/
fileassoc.cpp
139 lines (123 loc) · 3.67 KB
/
fileassoc.cpp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include "asspull.h"
bool IsAdmin()
{
BOOL res = FALSE;
DWORD dwError = ERROR_SUCCESS;
PSID pAdministratorsGroup = NULL;
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
if (!AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &pAdministratorsGroup))
{
dwError = GetLastError();
goto cleanup;
}
if (!CheckTokenMembership(NULL, pAdministratorsGroup, &res))
{
dwError = GetLastError();
goto cleanup;
}
cleanup:
if (pAdministratorsGroup)
{
FreeSid(pAdministratorsGroup);
pAdministratorsGroup = NULL;
}
if (dwError != ERROR_SUCCESS)
return false;
return res != FALSE;
}
void AssociateFiletypes()
{
WCHAR appPath[2048];
if (!IsAdmin())
{
GetModuleFileName(NULL, appPath, 2048);
SHELLEXECUTEINFO sei = { sizeof(sei) };
sei.lpVerb = L"runas";
sei.lpFile = appPath;
sei.lpParameters = L"--associate";
sei.hwnd = NULL;
sei.nShow = SW_NORMAL;
if (!ShellExecuteEx(&sei))
{
DWORD dwError = GetLastError();
if (dwError == ERROR_CANCELLED)
return;
}
return;
}
DWORD disp = 0;
HKEY key;
auto res = RegCreateKeyEx(HKEY_CLASSES_ROOT, L".ap3", 0, L"", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, &disp);
if (res == ERROR_SUCCESS)
{
res = RegSetValueEx(key, L"", 0, REG_SZ, (const UCHAR *)L"clunibus", 9 * 2);
RegCloseKey(key);
}
else
return;
res = RegCreateKeyEx(HKEY_CLASSES_ROOT, L".a3z", 0, L"", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, &disp);
if (res == ERROR_SUCCESS)
{
res = RegSetValueEx(key, L"", 0, REG_SZ, (const UCHAR *)L"clunibusz", 10 * 2);
RegCloseKey(key);
}
else
return;
GetModuleFileName(NULL, appPath, 2048);
WCHAR commandPath[2048];
wsprintf(commandPath, L"\"%s\" \"%%1\"", appPath);
res = RegCreateKeyEx(HKEY_CLASSES_ROOT, L"clunibus", 0, L"", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, &disp);
if (res == ERROR_SUCCESS)
{
HKEY key2;
res = RegSetValueEx(key, L"", 0, REG_SZ, (const UCHAR *)L"Clunibus ROM", 13 * 2);
res = RegCreateKeyEx(key, L"Shell\\Open\\Command", 0, L"", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key2, &disp);
if (res == ERROR_SUCCESS)
{
res = RegSetValueEx(key2, L"", 0, REG_SZ, (const UCHAR *)commandPath, wcslen(commandPath) * 2);
RegCloseKey(key2);
}
else
return;
res = RegCreateKeyEx(key, L"DefaultIcon", 0, L"", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key2, &disp);
if (res == ERROR_SUCCESS)
{
wsprintf(commandPath, L"%s,1", appPath);
res = RegSetValueEx(key2, L"", 0, REG_SZ, (const UCHAR *)commandPath, wcslen(commandPath) * 2);
RegCloseKey(key2);
}
else
return;
RegCloseKey(key);
}
else
return;
wsprintf(commandPath, L"\"%s\" \"%%1\"", appPath);
res = RegCreateKeyEx(HKEY_CLASSES_ROOT, L"clunibusz", 0, L"", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, &disp);
if (res == ERROR_SUCCESS)
{
HKEY key2;
res = RegSetValueEx(key, L"", 0, REG_SZ, (const UCHAR *)L"Clunibus zipped ROM", 13 * 2);
res = RegCreateKeyEx(key, L"Shell\\Open\\Command", 0, L"", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key2, &disp);
if (res == ERROR_SUCCESS)
{
res = RegSetValueEx(key2, L"", 0, REG_SZ, (const UCHAR *)commandPath, wcslen(commandPath) * 2);
RegCloseKey(key2);
}
else
return;
res = RegCreateKeyEx(key, L"DefaultIcon", 0, L"", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key2, &disp);
if (res == ERROR_SUCCESS)
{
wsprintf(commandPath, L"%s,2", appPath);
res = RegSetValueEx(key2, L"", 0, REG_SZ, (const UCHAR *)commandPath, wcslen(commandPath) * 2);
RegCloseKey(key2);
}
else
return;
RegCloseKey(key);
}
else
return;
MessageBox(NULL, L"Associations set.", L"Clunibus", MB_OK);
}