Forums: Code Enumerate Services - Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Code Enumerate Services

#1 User is offline   320X 

  • Master Sergeant
  • Icon
  • Group: Members
  • Posts: 473
  • Joined: 13-December 03

Posted 19 October 2005 - 11:49 AM

#include <stdio.h>
#include <Windows.h>

void main()
{
//Open the Service Control Manager
SC_HANDLE sc = ::OpenSCManager (NULL,NULL,SC_MANAGER_ENUMERATE_SERVICE);

//Check if OpenSCManager returns NULL. Otherwise proceed
if (sc != NULL)
{
printf("Opened SCM using OpenSCManager \n");
ENUM_SERVICE_STATUS service_data, *lpservice;
BOOL retVal;
DWORD bytesNeeded,srvCount,resumeHandle = 0,srvType, srvState;

srvType = SERVICE_WIN32;
srvState = SERVICE_STATE_ALL;

//Call EnumServicesStatus using the handle returned by OpenSCManager
retVal = ::EnumServicesStatus (sc,srvType,srvState,&service_data,sizeof(service_data),
&bytesNeeded,&srvCount,&resumeHandle);

DWORD err = GetLastError();
//Check if EnumServicesStatus needs more memory space
if ((retVal == FALSE) || err == ERROR_MORE_DATA)
{
DWORD dwBytes = bytesNeeded + sizeof(ENUM_SERVICE_STATUS);
lpservice = new ENUM_SERVICE_STATUS [dwBytes];
EnumServicesStatus (sc,srvType,srvState,lpservice,dwBytes,
&bytesNeeded,&srvCount,&resumeHandle);
}

printf("Count of NT Services using EnumServicesStatus : %d\n\n",srvCount);

for(int i=0;i<srvCount;i++)
{
printf("%s\n",lpservice[i].lpDisplayName);
}
}

//Close the SC_HANLDE returned by OpenSCManager
CloseServiceHandle(sc);

}
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users

  • Share



Our Sponsors:


SwiftLayer Affiliate Web Hosting