EnumServicesStatus 枚举系统服务
#include<iostream.h>
#include<windows.h>
#include<stdio.h>
#include<winsvc.h>
void main(int argc,char ** argv){
LPENUM_SERVICE_STATUS st;
st=(LPENUM_SERVICE_STATUS)LocalAlloc(LPTR,64*1024);
DWORD ret=0;
DWORD size=0;
HANDLE sc=OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
EnumServicesStatus(sc,SERVICE_WIN32,SERVICE_STATE_ALL, (LPENUM_SERVICE_STATUS)st,1024*64,&size,&ret,NULL);
for(int i=0;i<ret;i++){
printf("%-20s%-50s",st[i].lpServiceName,st[i].lpDisplayName);
switch(st[i].ServiceStatus.dwCurrentState){
case(SERVICE_RUNNING):
cout<<"running"<<endl;
break;
case(SERVICE_STOPPED):
cout<<"stopped"<<endl;
break;
}
}
}