Jump to content
YOUR-AD-HERE
HOSTING
TOOLS
992Proxy

Locked Obtener Servicios [C]


Expermicid

Recommended Posts

Continuando con un proyecto.

 

[LENGUAJE=c]#include "windows.h"

#include

 

int main()

{

DWORD i;

SC_HANDLE sc = OpenSCManager(NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE|GENERIC_READ);

 

if (sc != NULL) {

LPENUM_SERVICE_STATUS lpES = 0;

DWORD dwBuffSize = 0, dwBytesNeeded = 0, dwServicesReturned = 0, dwResumeHandle = 0;

 

BOOL bR = EnumServicesStatus(sc,SERVICE_WIN32,SERVICE_STATE_ALL,lpES,dwBuffSize,&dwBytesNeeded,&dwServicesReturned,&dwResumeHandle);

 

if ( bR != FALSE ) {

CloseServiceHandle(sc);

}

 

lpES = (LPENUM_SERVICE_STATUS) LocalAlloc(LPTR, dwBytesNeeded);

if ( lpES == 0 ) {

CloseServiceHandle(sc);

}

 

bR = EnumServicesStatus(sc,SERVICE_WIN32,SERVICE_STATE_ALL,lpES,dwBytesNeeded,&dwBytesNeeded,&dwServicesReturned,&dwResumeHandle);

 

LPENUM_SERVICE_STATUS lpCE = lpES;

 

for ( i = 0; i < dwServicesReturned; i++ ) {

 

printf(lpCE->lpServiceName);

printf(" ");

printf(lpCE->lpDisplayName);

printf(" ");

 

SERVICE_STATUS lpS = lpCE->ServiceStatus;

if ( lpS.dwCurrentState == SERVICE_CONTINUE_PENDING ) {

printf("Pendiente");

}

if ( lpS.dwCurrentState == SERVICE_PAUSE_PENDING) {

printf("Pendiente");

}

if ( lpS.dwCurrentState == SERVICE_PAUSED) {

printf("Pausado");

}

if ( lpS.dwCurrentState == SERVICE_RUNNING) {

printf("Corriendo");

}

if ( lpS.dwCurrentState == SERVICE_START_PENDING) {

printf("Iniciando");

}

if ( lpS.dwCurrentState == SERVICE_STOP_PENDING) {

printf("Deteniendo");

}

if ( lpS.dwCurrentState == SERVICE_STOPPED) {

printf("Parado");

}

 

printf("\n");

 

++lpCE;

}

 

LocalFree(lpES);

}

 

CloseServiceHandle(sc);

return 0;

}[/LENGUAJE]

 

Salida:

 

This is the hidden content, please

 

Aclaracion: La salida la muestro asi porque en la consola sale muy desprolijo pero esa seria la salida.

 

Saludos

Edited by Expermicid
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.