You will need to do this by interrogating. Put the code in a separate thread and send it to sleep until it is reasonable. Say every second, maybe even 5 seconds, to minimize system performance.
As an example of 'c' for one service:
// various descriptors and strings plus ... SERVICE_STATUS ssStatus; ...
schSCManager = OpenSCManager( ServiceComputerNameStr, NULL, SC_MANAGER_ALL_ACCESS ); if ( schSCManager == NULL ) { // ... error stuff goto cleanup; } scphService = OpenService( schSCManager, ServiceNameStr, // SERVICE_QUERY_STATUS ); SERVICE_ALL_ACCESS ); if ( scphService == NULL ) { // ... error stuff goto cleanup; } if ( !QueryServiceStatus(scphService, ssStatus) ) { // ... error stuff goto cleanup; }
The result you want will be in ssStatus.dwCurrentState.
source share