-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathProcessMisc.cpp
More file actions
65 lines (62 loc) · 1.87 KB
/
ProcessMisc.cpp
File metadata and controls
65 lines (62 loc) · 1.87 KB
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
#include "ProcessMisc.h"
std::wstring ReadRegistryDefaultValue(const std::wstring clsid)
{
HKEY hKey;
std::wstring subKey = L"CLSID\\{" + clsid + L"}\\InprocServer32";
wchar_t value[512]; // Adjust size as needed
DWORD valueLength = sizeof(value);
LONG result;
result = RegOpenKeyExW(HKEY_CLASSES_ROOT, subKey.c_str(), 0, KEY_READ, &hKey);
if (result != ERROR_SUCCESS)
{
std::wcerr << L"Failed to open registry key. Error: " << result << std::endl;
return L"";
}
result = RegQueryValueExW(hKey, nullptr, nullptr, nullptr, reinterpret_cast<LPBYTE>(value), &valueLength);
RegCloseKey(hKey);
if (result != ERROR_SUCCESS)
{
std::wcerr << L"Failed to read default value. Error: " << result << std::endl;
return L"";
}
return std::wstring(value);
}
bool SetDefaultInprocServer32(const std::wstring clsid, const std::wstring dllPath)
{
std::wstring keyPath = L"CLSID\\{" + clsid + L"}\\InprocServer32";
HKEY hKey;
LONG result;
// Open or create the registry key
result = RegCreateKeyExW(
HKEY_CLASSES_ROOT,
keyPath.c_str(),
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
NULL,
&hKey,
NULL
);
if (result != ERROR_SUCCESS)
{
std::wcerr << L"Failed to open or create registry key. Error: " << result << std::endl;
return false;
}
// Set the (Default) value
result = RegSetValueExW(
hKey,
NULL, // NULL sets the (Default) value
0,
REG_SZ,
reinterpret_cast<const BYTE*>(dllPath.c_str()),
static_cast<DWORD>((dllPath.size() + 1) * sizeof(wchar_t))
);
RegCloseKey(hKey);
if (result != ERROR_SUCCESS)
{
std::wcerr << L"Failed to set registry value. Error: " << result << std::endl;
return false;
}
return true;
}