能力值:
( LV4,RANK:50 )
|
-
-
2 楼
有专门的API
|
能力值:
( LV8,RANK:130 )
|
-
-
3 楼
In your NT Shell command prompt:
C:\test>tasklist /svc
|
能力值:
( LV8,RANK:130 )
|
-
-
4 楼
win32 API:
OpenSCManager(...
EnumServicesStatusExW(...
Check MSDN, your best friend.
|
能力值:
(RANK:1010 )
|
-
-
5 楼
可以参考下面文章,含源码
http://bbs.pediy.com/showthread.php?s=&threadid=29187
|
能力值:
( LV2,RANK:10 )
|
-
-
6 楼
#include "stdafx.h"
#include <malloc.h>
#include <stdio.h>
#include "shlwapi.h"
#pragma comment (lib,"shlwapi.lib")
#include "c:\\program files\\microsoft sdk\\include\\winsvc.h"
#pragma comment (lib,"c:\\program files\\microsoft sdk\\lib\\Advapi32.lib")
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
SC_HANDLE scHandle = OpenSCManager(NULL,NULL,SC_MANAGER_ENUMERATE_SERVICE);
if(scHandle ==NULL)return 0;
ENUM_SERVICE_STATUS_PROCESS* pessp = NULL;
DWORD dwBytesRequired;
DWORD dwTotalServices;
DWORD ResumeHandle = 0 ;
HANDLE scHOutPut;
AllocConsole();
scHOutPut = GetStdHandle(STD_OUTPUT_HANDLE);
BOOL bRet = EnumServicesStatusEx(scHandle,SC_ENUM_PROCESS_INFO ,\
SERVICE_WIN32,SERVICE_STATE_ALL,(LPBYTE)pessp,0,&dwBytesRequired,\
&dwTotalServices,&ResumeHandle,NULL);
DWORD dwBufferSize = dwBytesRequired;
if(bRet == 0)
{
DWORD dwError = GetLastError();
if(ERROR_MORE_DATA == dwError)
{
pessp = (ENUM_SERVICE_STATUS_PROCESS*)malloc(dwBytesRequired);
bRet = EnumServicesStatusEx(scHandle,SC_ENUM_PROCESS_INFO ,\
SERVICE_WIN32,SERVICE_STATE_ALL,(LPBYTE)pessp,dwBufferSize,&dwBytesRequired,\
&dwTotalServices,&ResumeHandle,NULL);
if(bRet == 0)return 0;
TCHAR* szOutput = (TCHAR*)malloc(1024);
for(DWORD i = 0 ; i < dwTotalServices ; i++)
{
LPBYTE pbDesc = NULL;
DWORD dwBytesNeeded = 0;
SC_HANDLE hService = OpenService(scHandle,pessp[i].lpServiceName,SERVICE_QUERY_CONFIG);
if(NULL == hService)continue ;
QueryServiceConfig2(hService,SERVICE_CONFIG_DESCRIPTION,pbDesc,0,&dwBytesNeeded);
DWORD dwError = GetLastError();
if(dwError != ERROR_INSUFFICIENT_BUFFER)continue;
DWORD dwDescSize = dwBytesNeeded;
pbDesc = (LPBYTE)malloc(dwBytesNeeded);
ZeroMemory(pbDesc,dwBytesNeeded);
if(0 == QueryServiceConfig2(hService,SERVICE_CONFIG_DESCRIPTION,pbDesc,dwDescSize,&dwBytesNeeded))
{free(pbDesc);continue;}
ZeroMemory(szOutput,512);
StrCpy(szOutput,"\r\n");
StrCat(szOutput,pessp[i].lpServiceName);
StrCat(szOutput,",");
StrCat(szOutput,pessp[i].lpDisplayName);
StrCat(szOutput,",");
StrCat(szOutput,(const char*)(((SERVICE_DESCRIPTION*)pbDesc)->lpDescription));
WriteConsole(scHOutPut,szOutput,strlen(szOutput),NULL,0);
free(pbDesc);
CloseServiceHandle(hService);
}
CloseServiceHandle(scHandle);
free(szOutput);
free(pessp);
}
else return 0;
}
return 0;
}
|