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: public:
enum State { enum State {
StateActive = 0x01, StateActive = 0x01, // SERVICE_ACTIVE
StateInactive = 0x02, StateInactive = 0x02, // SERVICE_INACTIVE
StateAlive = (StateActive | StateInactive), // SERVICE_STATE_ALL
StateDeleted = 0x04, 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 auto serviceName = QString::fromUtf16((const char16_t *) service->lpServiceName);
const RegKey svcReg(servicesReg, serviceName); const RegKey svcReg(servicesReg, serviceName);
if (!svcReg.contains("ServiceSidType")) if (!svcReg.contains("ServiceSidType")
|| svcReg.value("SvcHostSplitDisable").toInt() != 0)
continue; continue;
const auto imagePath = svcReg.value("ImagePath").toString(); const auto imagePath = svcReg.value("ImagePath").toString();
@ -65,13 +66,13 @@ int ServiceInfoManager::groupIndexByName(const QString &name) const
return m_serviceGroups.value(name, -1); return m_serviceGroups.value(name, -1);
} }
QVector<ServiceInfo> ServiceInfoManager::loadServiceInfoList() QVector<ServiceInfo> ServiceInfoManager::loadServiceInfoList(ServiceInfo::State state)
{ {
QVector<ServiceInfo> list; QVector<ServiceInfo> list;
const SC_HANDLE mngr = const SC_HANDLE mngr =
OpenSCManagerW(nullptr, nullptr, SC_MANAGER_CONNECT | SC_MANAGER_ENUMERATE_SERVICE); OpenSCManagerW(nullptr, nullptr, SC_MANAGER_CONNECT | SC_MANAGER_ENUMERATE_SERVICE);
if (mngr) { if (mngr) {
list = getServiceInfoList(mngr); list = getServiceInfoList(mngr, state);
CloseServiceHandle(mngr); CloseServiceHandle(mngr);
} }
return list; return list;

View File

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