IT Management Daily
Storage Daily
Security Daily
FREE NEWSLETTERS
search
 

follow us on Twitter


internet.commerce
Be a Commerce Partner















internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers




Products
 LinqConnect Express (LinqConnect Express)
 LinqConnect 2.00 (Devart)
 EMS SQL Manager for MySQL (EMS Database Management Solutions, Inc.)
 EMS SQL Management Studio for MySQL (EMS Database Management Solutions, Inc.)
 Database Designer for PostgreSQL (MicroOLAP Technologies LTD)
 ESBFinCalc Pro - Financial Calculator (ESB Consultancy)
» Enterprise IT Planet » Resources » Win Scripts

Enumerate NT Services in a System

July 1, 2004

Email Print Digg This Add to del.icio.us
Author: Muthukumar.V
Platform: Windows

DESCRIPTION: Every machine installed with Windows NT Operating system and above will have NT services running with it. Developers will also write some Win32 NT Services for applications. This article describes how to enumerate the NT Services installed in the system using the Win32 API EnumServicesStatus.

Click here to download the script.

Scroll down to view the script.


#include
#include
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 {
printf("%s\n",lpservice[i].lpDisplayName);
}
}
//Close the SC_HANLDE returned by OpenSCManager
CloseServiceHandle(sc);
}

Disclaimer: We hope that the information in these pages is valuable to you. Your use of the information contained in these pages, however, is at your sole risk. All information on these pages is provided "as - is", without any warranty, whether express or implied, of its accuracy, completeness, fitness for a particular purpose, title or non-infringement, and none of the third-party products or information mentioned in the work are authored, recommended, supported or guaranteed by me. I shall not be liable for any damages you may sustain by using this information, whether direct, indirect, special, incidental or consequential, even if it has been advised of the possibility of such damages.

Email Print Digg This Add to del.icio.us

Win Scripts Archives