003
09.03.2006, 14:31 Uhr
Uwe
C/C++ Master (Administrator)
|
Hallo, so ganz versteh ich nicht was Du bezweckst:
C++: |
#include <windows.h> #include <iostream> using namespace std;
void Err(DWORD);
int main() { SC_HANDLE hHandle = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (NULL == hHandle) { Err(GetLastError()); return -1; } else { cout << "SCM geöffnet." << endl; }
ENUM_SERVICE_STATUS sv; DWORD dwBytes = 0; DWORD dwServices = 0; DWORD dwResumedHandle = 0; DWORD dwService = SERVICE_WIN32 | SERVICE_DRIVER;
BOOL ret = EnumServicesStatus(hHandle, dwService, SERVICE_STATE_ALL, &sv, sizeof(ENUM_SERVICE_STATUS), &dwBytes, &dwServices, &dwResumedHandle);
if (!ret) { // Buffer setzen if (ERROR_MORE_DATA == GetLastError()) { DWORD dwBuffer = sizeof(ENUM_SERVICE_STATUS) + dwBytes; ENUM_SERVICE_STATUS* pServices = NULL; pServices = new ENUM_SERVICE_STATUS [dwBuffer];
EnumServicesStatus(hHandle, SERVICE_WIN32 | SERVICE_DRIVER, SERVICE_STATE_ALL, pServices, dwBuffer, &dwBytes, &dwServices, &dwResumedHandle); // Ausgabe for (unsigned iIndex = 0; iIndex < dwServices; iIndex++) { cout << TEXT("Anzeige Name: ") << (pServices + iIndex)->lpDisplayName << TEXT('\t'); cout << TEXT("Service Name: ") << (pServices + iIndex)->lpServiceName << endl; }
delete [] pServices; pServices = NULL;
} else { Err(GetLastError()); } }
if (!CloseServiceHandle(hHandle)) { Err(GetLastError()); } else { cout << "SCM geschlossen." << endl; } return 0; }
// Fehler auswerten void Err(DWORD pE) { HLOCAL hLocal = NULL; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, pE, MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN),(LPTSTR)&hLocal, 0, NULL); MessageBox(NULL, (LPCTSTR)LocalLock(hLocal), TEXT("Error"), MB_OK | MB_ICONERROR); LocalFree(hLocal); }
|
Die Konsole App sollte Dir die Services auflisten. -- "Es ist schwierig, ein Programm wirklich idiotensicher zu machen, weil Idioten so genial sind."
Bis dann... Uwe Dieser Post wurde am 09.03.2006 um 14:36 Uhr von Uwe editiert. |