Alle laufenden Dienste ermitteln
-
Hallo liebe Community,
und zwar suche ich eine möglichkeit mit der ich alle laufenden Dienste auf dem PC(Betriebssystem ist natürlich Windows) ermitteln kann.
Eine Funktion zum ermitteln der Dienste ist mir nicht bekannt.
Ich hoffe ihr könnt mir etwas weiter helfen.

-
Vielleicht: EnumServicesStatusEx
-
Dann wolln wir Dich mal erleuchten:
#pragma comment( lib, "advapi32.lib" ) #define UNICODE #define _UNICODE #include <string> #include <iostream> namespace std_ext { #ifdef UNICODE std::wostream &tcout( std::wcout ); std::wostream &tcerr( std::wcerr ); std::wistream &tcin( std::wcin ); typedef std::basic_string< wchar_t > tstring; #elif std::ostream &tcout( std::cout ); std::ostream &tcerr( std::cerr ); std::istream &tcin( std::cin ); typedef std::string tstring; #endif /* UNICODE */ } #include <windows.h> #include <tchar.h> namespace winapi_tools { std_ext::tstring get_last_error_msg( ) { void *message_buffer = 0; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, GetLastError( ), MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), reinterpret_cast< LPTSTR >( &message_buffer ), 0, 0 ); std_ext::tstring error_message( reinterpret_cast< LPTSTR >( message_buffer ) ); LocalFree( message_buffer ); return error_message; } } int main( ) { SC_HANDLE service_control = OpenSCManager( 0, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ENUMERATE_SERVICE ); if( !service_control ) { std_ext::tcerr << _T( "Error: " ) << winapi_tools::get_last_error_msg( ) << std::endl; return EXIT_FAILURE; } unsigned long bytes_needed( 0 ); unsigned long num_services( 0 ); unsigned long resume_handle( 0 ); /* unused */ if( !EnumServicesStatusEx( service_control, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_ACTIVE, 0, 0, &bytes_needed, &num_services, &resume_handle, 0 ) && ( GetLastError( ) != ERROR_MORE_DATA ) ) { std_ext::tcerr << _T( "Error: " ) << winapi_tools::get_last_error_msg( ) << std::endl; return EXIT_FAILURE; } unsigned char *service_status_bytes = 0; try { service_status_bytes = new unsigned char[ bytes_needed ]; } catch( std::bad_alloc &e ) { std_ext::tcerr << _T( "Not enough memory!\n" ) << std::endl; return EXIT_FAILURE; } if( !EnumServicesStatusEx( service_control, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_ACTIVE, service_status_bytes, bytes_needed, &bytes_needed, &num_services, &resume_handle, 0 ) ) { std_ext::tcerr << _T( "Error: " ) << winapi_tools::get_last_error_msg( ) << std::endl; return EXIT_FAILURE; } ENUM_SERVICE_STATUS_PROCESS *service_status = reinterpret_cast< ENUM_SERVICE_STATUS_PROCESS* >( service_status_bytes ); for( unsigned long i( 0 ); i < num_services; ++i ) { std_ext::tcout.width( 3 ); std_ext::tcout.fill( _T( ' ' ) ); std_ext::tcout << i << _T( ": " ) << service_status[ i ].lpDisplayName << _T( " (" ) << service_status[ i ].lpServiceName << _T( ")" ) << std::endl; } delete[ ] service_status; }greetz, Swordfish
-
Versuche es mal mit EnumWindows().
-
berniebutt schrieb:
Versuche es mal mit EnumWindows().
rofl