• 列举Windows服务


    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_SHARE_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( '读取服务状态失败,错误: '+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));
           }
        }
    }


     以上代码需引用winsvc.h文件,为C++Builder2010编写,基本就是两个api,但不知为何所有的服务都列出来的,单单就是我用C++Builder2010写的一个服务程序无法找到??

  • 相关阅读:
    window.open和window.opener
    dict对象与QueryDict
    BeautifulSoup的一些方法
    ORM分组与聚合
    python-orm
    开发工具IDEA环境安装配置
    Greenplum介绍-table
    对package.json的理解和学习
    javaScript 的 map() reduce() foreach() filter()
    JSON的序列化和反序列化eval()和parse()方法以及stringfy()方法
  • 原文地址:https://www.cnblogs.com/81/p/1945231.html
Copyright © 2020-2023  润新知