| 438 | } |
| 439 | |
| 440 | LRESULT CServiceTable::OnServiceStart(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { |
| 441 | int selected = m_Table.data.selected; |
| 442 | ATLASSERT(selected >= 0); |
| 443 | auto& svc = m_Table.data.info[selected]; |
| 444 | |
| 445 | auto service = Service::Open(svc.GetName(), ServiceAccessMask::Start | ServiceAccessMask::QueryStatus); |
| 446 | if (service == nullptr) { |
| 447 | AtlMessageBox(*this, L"Failed to open service", IDS_TITLE, MB_ICONERROR); |
| 448 | return 0; |
| 449 | } |
| 450 | |
| 451 | if (!service->Start()) { |
| 452 | AtlMessageBox(*this, L"Failed to start service", IDS_TITLE, MB_ICONERROR); |
| 453 | return 0; |
| 454 | } |
| 455 | |
| 456 | CProgressDlg dlg; |
| 457 | dlg.ShowCancelButton(false); |
| 458 | dlg.SetMessageText((L"Starting service" + svc.GetName() + L"...").c_str()); |
| 459 | dlg.SetProgressMarquee(true); |
| 460 | auto now = ::GetTickCount64(); |
| 461 | dlg.SetTimerCallback([&]() { |
| 462 | service->Refresh(svc); |
| 463 | if (svc.GetStatusProcess().CurrentState == ServiceState::Running) |
| 464 | dlg.Close(); |
| 465 | if (::GetTickCount64() - now > 5000) |
| 466 | dlg.Close(IDCANCEL); |
| 467 | }, 500); |
| 468 | if (dlg.DoModal() == IDCANCEL) { |
| 469 | AtlMessageBox(*this, L"Failed to start service within 5 seconds", IDS_TITLE, MB_ICONEXCLAMATION); |
| 470 | } |
| 471 | Refresh(); |
| 472 | |
| 473 | return 0; |
| 474 | } |
| 475 | |
| 476 | LRESULT CServiceTable::OnServiceStop(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { |
| 477 | int selected = m_Table.data.selected; |
nothing calls this directly
no test coverage detected