-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy pathmain.7.c
35 lines (33 loc) · 1.24 KB
/
main.7.c
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
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0600
#endif
#include <windows.h>
void launch_at_startup(int is_launch_at_startup){
HKEY hKey;
const wchar_t* run_key_path = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
wchar_t path[UTOX_FILE_NAME_LENGTH*2];
uint16_t path_length = 0, ret = 0;
if(is_launch_at_startup == 1){
if(ERROR_SUCCESS == RegOpenKeyW(HKEY_CURRENT_USER, run_key_path, &hKey)){
path_length = GetModuleFileNameW(NULL, path+1, UTOX_FILE_NAME_LENGTH*2);
path[0] = '\"';
path[path_length+1] = '\"';
path[path_length+2] = '\0';
path_length += 2;
ret = RegSetKeyValueW(hKey, NULL, (LPCSTR)(L"uTox"), REG_SZ, path, path_length*2); /*2 bytes per wchar */
if(ret == ERROR_SUCCESS){
debug("Successful auto start addition.\n");
}
RegCloseKey(hKey);
}
}
if(is_launch_at_startup == 0){
if(ERROR_SUCCESS == RegOpenKeyW(HKEY_CURRENT_USER, run_key_path, &hKey)){
ret = RegDeleteKeyValueW(hKey, NULL, L"uTox");
if(ret == ERROR_SUCCESS){
debug("Successful auto start deletion.\n");
}
RegCloseKey(hKey);
}
}
}