Tstringlist * Listservices ( Int Servicetype)
{
Tstringlist * List = New Tstringlist ();
SC _handle schscmanager = Openscmanager (null, null, SC _manager_all_access );
Lpbyte lpservices;
Dword n, nsize, npsize, nservicesreturned, nresumehandle, dwservicetype;
If (Schscmanager > 0 )
{
Nresumehandle = 0 ;
Npsize = Sizeof (Enum_service_status_process );
Dwservicetype = Service_win32 | Service_driver |
Service_kernel_driver | Service_file_system_driver |
Service_win32_own_process | Service_win32_assist_process;
Lpservices = Lpbyte (localalloc (lptr, 30720 ));
Try
{
If ( ! Enumservicesstatusex (schscmanager, SC _enum_process_info,
Dwservicetype, service_state_all, lpservices, 30720 ,
& Nsize, & Nservicesreturned, & Nresumehandle, null ))
{
// P_showerror ('failed to read service status, error: '+ inttostr (getlasterror ));
Return List;
}
For (N = 0 ; N < Nservicesreturned - 1 ; N ++ )
{
// Show the name of service
// Listitem: = svclistview. Items. Add;
// Listitem. Caption: = (lpenum_service_status_process (lpservices) ^. lpservicename;
// Listitem. subitems. Add (lpenum_service_status_process (lpservices) ^. lpdisplayname );
// Listitem. subitems. Add (inttostr (lpenum_service_status_process (lpservices) ^. servicestatusprocess. dwprocessid ));
// Listitem. subitems. Add (srvstatus (lpenum_service_status_process (lpservices) ^. servicestatusprocess. dwcurrentstate ));
String SS = (Lpenum_service_status_process (lpservices )) -> Lpservicename;
String ss2 = (Lpenum_service_status_process (lpservices )) -> Lpdisplayname;
List -> Add (ss2 );
If (Ss2 = " Wwservices " ){
Showmessage (ss2 );
}
Lpservices + = Npsize;
}
Return List;
}
_ Finally
{
//If (lpservices! = NULL)
//Localfree (INT (lpservices ));
}
}
}
AboveCodeYou must reference winsvc. h file, written for C ++ builder2010, is basically two APIs, but somehow all services are listed, just a service I wrote using C ++ builder2010ProgramCannot find ??