31 GetRegString(HKEY
key, LPCTSTR value, LPTSTR data, DWORD size, LPCTSTR default_value)
33 LONG
status = RegGetValue(
key, NULL, value, RRF_RT_REG_SZ,
34 NULL, (LPBYTE) data, &size);
36 if (
status == ERROR_FILE_NOT_FOUND && default_value)
38 size_t len = size/
sizeof(data[0]);
39 if (swprintf(data, len, default_value))
45 if (
status != ERROR_SUCCESS)
63 TCHAR install_path[MAX_PATH];
64 TCHAR default_value[MAX_PATH];
68 LONG
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, reg_path, 0, KEY_READ, &
key);
69 if (
status != ERROR_SUCCESS)
77 if (
status != ERROR_SUCCESS)
83 swprintf(default_value, _countof(default_value), TEXT(
"%ls\\bin\\openvpn.exe"),
86 if (error != ERROR_SUCCESS)
91 swprintf(default_value, _countof(default_value), TEXT(
"%ls\\config"), install_path);
94 if (error != ERROR_SUCCESS)
101 if (error != ERROR_SUCCESS)
106 swprintf(default_value, _countof(default_value), TEXT(
"%ls\\log"), install_path);
108 if (error != ERROR_SUCCESS)
113 error =
GetRegString(
key, TEXT(
"priority"), priority,
sizeof(priority),
114 TEXT(
"NORMAL_PRIORITY_CLASS"));
115 if (error != ERROR_SUCCESS)
120 error =
GetRegString(
key, TEXT(
"log_append"), append,
sizeof(append), TEXT(
"0"));
121 if (error != ERROR_SUCCESS)
129 if (error != ERROR_SUCCESS)
134 if (!_wcsicmp(priority, TEXT(
"IDLE_PRIORITY_CLASS")))
138 else if (!_wcsicmp(priority, TEXT(
"BELOW_NORMAL_PRIORITY_CLASS")))
140 s->
priority = BELOW_NORMAL_PRIORITY_CLASS;
142 else if (!_wcsicmp(priority, TEXT(
"NORMAL_PRIORITY_CLASS")))
144 s->
priority = NORMAL_PRIORITY_CLASS;
146 else if (!_wcsicmp(priority, TEXT(
"ABOVE_NORMAL_PRIORITY_CLASS")))
148 s->
priority = ABOVE_NORMAL_PRIORITY_CLASS;
150 else if (!_wcsicmp(priority, TEXT(
"HIGH_PRIORITY_CLASS")))
156 SetLastError(ERROR_INVALID_DATA);
162 if (append[0] == TEXT(
'0'))
166 else if (append[0] == TEXT(
'1'))
172 SetLastError(ERROR_INVALID_DATA);
173 error =
MsgToEventLog(
M_ERR, TEXT(
"Log file append flag (given as '%ls') must be '0' or '1'"), append);
187 static TCHAR buf[256];
191 error = GetLastError();
192 len = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY,
193 NULL, error, LANG_NEUTRAL, tmp, 0, NULL);
195 if (len == 0 || (
long) _countof(buf) < (
long) len + 14)
201 tmp[wcslen(tmp) - 2] = TEXT(
'\0');
202 swprintf(buf, _countof(buf), TEXT(
"%ls (0x%x)"), tmp, error);
220 LPCTSTR err_msg = TEXT(
"");
225 error = GetLastError();
229 hEventSource = RegisterEventSource(NULL,
APPNAME);
230 if (hEventSource != NULL)
232 swprintf(
msg[0], _countof(
msg[0]),
236 va_start(arglist, format);
237 vswprintf(
msg[1], _countof(
msg[1]), format, arglist);
240 const TCHAR *mesg[] = {
msg[0],
msg[1] };
242 EVENTLOG_ERROR_TYPE : EVENTLOG_INFORMATION_TYPE,
243 0, 0, NULL, 2, 0, mesg, NULL);
244 DeregisterEventSource(hEventSource);
254 int n = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0);
255 wchar_t *utf16 = malloc(n *
sizeof(
wchar_t));
260 MultiByteToWideChar(CP_UTF8, 0, utf8, -1, utf16, n);
267 const wchar_t *default_sys_path = L
"C:\\Windows\\system32";