MCPcopy Create free account
hub / github.com/BeneficialCode/WinArk / InstallService

Function InstallService

WinArkSvc/WinArkSvc.cpp:289–316  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

287}
288
289int InstallService() {
290 SC_HANDLE hScm = ::OpenSCManager(nullptr, nullptr, SC_MANAGER_CREATE_SERVICE);
291 if (!hScm)
292 return Error("Failed to open SCM database");
293
294 WCHAR path[MAX_PATH];
295 ::GetModuleFileName(nullptr, path, _countof(path));
296
297 SC_HANDLE hService = ::CreateService(hScm,
298 L"WinArkSvc",
299 L"WinArk Demo Service",
300 SERVICE_ALL_ACCESS,
301 SERVICE_WIN32_OWN_PROCESS,
302 SERVICE_DEMAND_START,
303 SERVICE_ERROR_NORMAL,
304 path,
305 L"Base",
306 nullptr, nullptr, L"NT AUTHORITY\\LocalService", nullptr);
307 if (!hService)
308 return Error("Failed to install service");
309
310 printf("Service installed successfully.\n");
311
312 ::CloseServiceHandle(hService);
313 ::CloseServiceHandle(hScm);
314
315 return 0;
316}
317
318int StartWinArkService() {
319 SC_HANDLE hScm = ::OpenSCManager(nullptr, nullptr, SC_MANAGER_CONNECT);

Callers 1

HandleCommandLineFunction · 0.85

Calls 1

ErrorFunction · 0.70

Tested by

no test coverage detected