List Windows Services

Source: Internet
Author: User
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 ??

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.