ServiceInfoManager::loadServiceInfoList: Add filter by state

This commit is contained in:
Nodir Temirkhodjaev 2022-02-05 20:10:07 +03:00
parent caf754c7a0
commit 3c360f0d97
3 changed files with 9 additions and 6 deletions

View File

@ -7,8 +7,9 @@ class ServiceInfo
{
public:
enum State {
StateActive = 0x01,
StateInactive = 0x02,
StateActive = 0x01, // SERVICE_ACTIVE
StateInactive = 0x02, // SERVICE_INACTIVE
StateAlive = (StateActive | StateInactive), // SERVICE_STATE_ALL
StateDeleted = 0x04,
};

View File

@ -34,7 +34,8 @@ QVector<ServiceInfo> getServiceInfoList(SC_HANDLE mngr, DWORD state = SERVICE_ST
const auto serviceName = QString::fromUtf16((const char16_t *) service->lpServiceName);
const RegKey svcReg(servicesReg, serviceName);
if (!svcReg.contains("ServiceSidType"))
if (!svcReg.contains("ServiceSidType")
|| svcReg.value("SvcHostSplitDisable").toInt() != 0)
continue;
const auto imagePath = svcReg.value("ImagePath").toString();
@ -65,13 +66,13 @@ int ServiceInfoManager::groupIndexByName(const QString &name) const
return m_serviceGroups.value(name, -1);
}
QVector<ServiceInfo> ServiceInfoManager::loadServiceInfoList()
QVector<ServiceInfo> ServiceInfoManager::loadServiceInfoList(ServiceInfo::State state)
{
QVector<ServiceInfo> list;
const SC_HANDLE mngr =
OpenSCManagerW(nullptr, nullptr, SC_MANAGER_CONNECT | SC_MANAGER_ENUMERATE_SERVICE);
if (mngr) {
list = getServiceInfoList(mngr);
list = getServiceInfoList(mngr, state);
CloseServiceHandle(mngr);
}
return list;

View File

@ -17,7 +17,8 @@ public:
int groupIndexByName(const QString &name) const;
static QVector<ServiceInfo> loadServiceInfoList();
static QVector<ServiceInfo> loadServiceInfoList(
ServiceInfo::State state = ServiceInfo::StateAlive);
private:
QHash<QString, int> m_serviceGroups;