Changeset 8f167e8 in nscp
- Timestamp:
- 06/14/08 18:06:38 (5 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2, stable
- Children:
- dff5db9
- Parents:
- eb30340
- Location:
- include
- Files:
-
- 2 edited
-
EnumNtSrv.cpp (modified) (7 diffs)
-
EnumNtSrv.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
include/EnumNtSrv.cpp
r978bd31 r8f167e8 136 136 // dwType = bit OR of SERVICE_WIN32, SERVICE_DRIVER 137 137 // dwState = bit OR of SERVICE_ACTIVE, SERVICE_INACTIVE 138 TNtServiceInfo *TNtServiceInfo::EnumServices(DWORD dwType, DWORD dwState, DWORD *pdwCount)139 { 140 ASSERT(pdwCount != NULL);138 TNtServiceInfoList TNtServiceInfo::EnumServices(DWORD dwType, DWORD dwState) 139 { 140 TNtServiceInfoList ret; 141 141 // Maybe check if dwType and dwState have at least one constant specified 142 *pdwCount = 0;143 TNtServiceInfo *info = NULL;144 142 SC_HANDLE scman = ::OpenSCManager(NULL,NULL,SC_MANAGER_ENUMERATE_SERVICE); 145 143 if (scman) { … … 154 152 ::EnumServicesStatus(scman,dwType,dwState,lpservice,bytes, 155 153 &bytesNeeded,&servicesReturned,&resumeHandle); 156 *pdwCount = servicesReturned; // Not a chance that 0 services is returned157 info = new TNtServiceInfo [servicesReturned];158 154 TCHAR Buffer[1024]; // Should be enough for service info 159 155 QUERY_SERVICE_CONFIG *lpqch = (QUERY_SERVICE_CONFIG*)Buffer; 160 156 for (DWORD ndx = 0; ndx < servicesReturned; ndx++) { 161 info[ndx].m_strServiceName = lpservice[ndx].lpServiceName; 162 info[ndx].m_strDisplayName = lpservice[ndx].lpDisplayName; 163 info[ndx].m_dwServiceType = lpservice[ndx].ServiceStatus.dwServiceType; 164 info[ndx].m_dwCurrentState = lpservice[ndx].ServiceStatus.dwCurrentState; 157 TNtServiceInfo info; 158 info.m_strServiceName = lpservice[ndx].lpServiceName; 159 info.m_strDisplayName = lpservice[ndx].lpDisplayName; 160 info.m_dwServiceType = lpservice[ndx].ServiceStatus.dwServiceType; 161 info.m_dwCurrentState = lpservice[ndx].ServiceStatus.dwCurrentState; 165 162 SC_HANDLE sh = ::OpenService(scman,lpservice[ndx].lpServiceName,SERVICE_QUERY_CONFIG); 166 163 if (::QueryServiceConfig(sh,lpqch,sizeof(Buffer),&bytesNeeded)) { 167 info [ndx].m_strBinaryPath = lpqch->lpBinaryPathName;168 info [ndx].m_dwStartType = lpqch->dwStartType;169 info [ndx].m_dwErrorControl = lpqch->dwErrorControl;164 info.m_strBinaryPath = lpqch->lpBinaryPathName; 165 info.m_dwStartType = lpqch->dwStartType; 166 info.m_dwErrorControl = lpqch->dwErrorControl; 170 167 } 171 168 ::CloseServiceHandle(sh); 169 ret.push_back(info); 172 170 } 173 171 delete [] lpservice; … … 175 173 ::CloseServiceHandle(scman); 176 174 } 177 return info; 178 } 175 return ret; 176 } 177 179 178 180 179 #define SC_BUF_LEN 4096 … … 193 192 if (GetServiceKeyName(scman, name.c_str(), buf, &bufLen) == 0) { 194 193 ::CloseServiceHandle(scman); 194 delete [] buf; 195 195 throw NTServiceException(name, _T("GetServiceKeyName: Could not translate service name"), GetLastError()); 196 196 } … … 204 204 */ 205 205 sh = ::OpenService(scman,buf,SERVICE_QUERY_STATUS); 206 delete [] buf; 206 207 if (sh == NULL) { 207 208 ::CloseServiceHandle(scman); … … 224 225 } 225 226 226 227 /* 227 228 // Enumerate services on this machine and return an STL list of service objects 228 229 // dwType = bit OR of SERVICE_WIN32, SERVICE_DRIVER … … 239 240 delete [] pSrvList; 240 241 } 241 242 */ 242 243 /*############################################################################# 243 244 # End of file ENUMNTSRV.CPP -
include/EnumNtSrv.h
r99e4d8f r8f167e8 70 70 std::wstring GetCurrentState(void); 71 71 72 static TNtServiceInfo *EnumServices(DWORD dwType, DWORD dwState, DWORD *pdwCount);73 static void EnumServices(DWORD dwType, DWORD dwState, TNtServiceInfoList *pList);72 static TNtServiceInfoList EnumServices(DWORD dwType, DWORD dwState); 73 //static void EnumServices(DWORD dwType, DWORD dwState, TNtServiceInfoList *pList); 74 74 static TNtServiceInfo GetService(std::wstring); 75 75 };
Note: See TracChangeset
for help on using the changeset viewer.








