| 287 | } |
| 288 | |
| 289 | int 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 | |
| 318 | int StartWinArkService() { |
| 319 | SC_HANDLE hScm = ::OpenSCManager(nullptr, nullptr, SC_MANAGER_CONNECT); |
no test coverage detected