24 static DWORD dwCheckPoint = 1;
27 if (
status->dwCurrentState == SERVICE_START_PENDING)
29 status->dwControlsAccepted = 0;
33 status->dwControlsAccepted = SERVICE_ACCEPT_STOP;
36 if (
status->dwCurrentState == SERVICE_RUNNING
37 ||
status->dwCurrentState == SERVICE_STOPPED)
43 status->dwCheckPoint = dwCheckPoint++;
60 SC_HANDLE svc_ctl_mgr;
64 if (GetModuleFileName(NULL, path + 1, _countof(path) - 2) == 0)
71 wcscat_s(path, _countof(path), TEXT(
"\""));
73 svc_ctl_mgr = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT | SC_MANAGER_CREATE_SERVICE);
74 if (svc_ctl_mgr == NULL)
82 service = CreateService(svc_ctl_mgr,
86 SERVICE_WIN32_SHARE_PROCESS,
104 CloseServiceHandle(svc_ctl_mgr);
113 SC_HANDLE svc_ctl_mgr;
116 svc_ctl_mgr = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
117 if (svc_ctl_mgr == NULL)
126 if (StartService(
service, 0, NULL))
128 wprintf(TEXT(
"Service Started\n"));
143 CloseServiceHandle(svc_ctl_mgr);
152 SC_HANDLE svc_ctl_mgr;
156 svc_ctl_mgr = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
157 if (svc_ctl_mgr == NULL)
167 DELETE | SERVICE_STOP | SERVICE_QUERY_STATUS);
182 if (
status.dwCurrentState == SERVICE_STOP_PENDING)
193 if (
status.dwCurrentState == SERVICE_STOPPED)
195 wprintf(TEXT(
"\n%ls stopped.\n"), ovpn_svc->
display_name);
199 wprintf(TEXT(
"\n%ls failed to stop.\n"), ovpn_svc->
display_name);
206 wprintf(TEXT(
"%ls removed.\n"), ovpn_svc->
display_name);
218 CloseServiceHandle(svc_ctl_mgr);
230 const SERVICE_TABLE_ENTRY dispatchTable_shared[] = {
236 const SERVICE_TABLE_ENTRY dispatchTable_interactive[] = {
241 const SERVICE_TABLE_ENTRY *dispatchTable = dispatchTable_shared;
245 for (
int i = 1; i < argc; i++)
247 if (*
argv[i] == TEXT(
'-') || *
argv[i] == TEXT(
'/'))
249 if (_wcsicmp(TEXT(
"install"),
argv[i] + 1) == 0)
253 else if (_wcsicmp(TEXT(
"remove"),
argv[i] + 1) == 0)
257 else if (_wcsicmp(TEXT(
"start"),
argv[i] + 1) == 0)
261 else if (argc > i + 2 && _wcsicmp(TEXT(
"instance"),
argv[i] + 1) == 0)
263 if (_wcsicmp(TEXT(
"interactive"),
argv[i+1]) == 0)
265 dispatchTable = dispatchTable_interactive;
277 wprintf(TEXT(
"%ls -install to install the interactive service\n"),
APPNAME);
278 wprintf(TEXT(
"%ls -start [name] to start the service (name = \"interactive\" is optional)\n"),
APPNAME);
279 wprintf(TEXT(
"%ls -remove to remove the service\n"),
APPNAME);
281 wprintf(TEXT(
"\nService run-time parameters:\n"));
282 wprintf(TEXT(
"-instance interactive <id>\n")
283 TEXT(
" Runs the service as an alternate instance.\n")
284 TEXT(
" The service settings will be loaded from\n")
285 TEXT(
" HKLM\\Software\\" PACKAGE_NAME "<id> registry key, and the service will accept\n")
286 TEXT(
" requests on \\\\.\\pipe\\" PACKAGE "<id>\\service named pipe.\n"));
297 wprintf(TEXT(
"\nStartServiceCtrlDispatcher being called.\n"));
298 wprintf(TEXT(
"This may take several seconds. Please wait.\n"));
300 if (!StartServiceCtrlDispatcher(dispatchTable))