| 516 | } |
| 517 | |
| 518 | Service::StartType getServiceStartType(SC_HANDLE s, const QString& name) |
| 519 | { |
| 520 | DWORD needed = 0; |
| 521 | |
| 522 | if (!QueryServiceConfig(s, NULL, 0, &needed)) { |
| 523 | const auto e = GetLastError(); |
| 524 | |
| 525 | if (e != ERROR_INSUFFICIENT_BUFFER) { |
| 526 | log::error("QueryServiceConfig() for size for '{}' failed, {}", name, |
| 527 | GetLastError()); |
| 528 | |
| 529 | return Service::StartType::None; |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | const auto size = needed; |
| 534 | MallocPtr<QUERY_SERVICE_CONFIG> config( |
| 535 | static_cast<QUERY_SERVICE_CONFIG*>(std::malloc(size))); |
| 536 | |
| 537 | if (!QueryServiceConfig(s, config.get(), size, &needed)) { |
| 538 | const auto e = GetLastError(); |
| 539 | |
| 540 | log::error("QueryServiceConfig() for '{}' failed", name, formatSystemMessage(e)); |
| 541 | |
| 542 | return Service::StartType::None; |
| 543 | } |
| 544 | |
| 545 | switch (config->dwStartType) { |
| 546 | case SERVICE_AUTO_START: // fall-through |
| 547 | case SERVICE_BOOT_START: |
| 548 | case SERVICE_DEMAND_START: |
| 549 | case SERVICE_SYSTEM_START: { |
| 550 | return Service::StartType::Enabled; |
| 551 | } |
| 552 | |
| 553 | case SERVICE_DISABLED: { |
| 554 | return Service::StartType::Disabled; |
| 555 | } |
| 556 | |
| 557 | default: { |
| 558 | log::error("unknown service start type {} for '{}'", config->dwStartType, name); |
| 559 | |
| 560 | return Service::StartType::None; |
| 561 | } |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | Service::Status getServiceStatus(SC_HANDLE s, const QString& name) |
| 566 | { |