Delphi如何获取系统服务(即Service服务程序)列表
来源:互联网 发布:php转盘抽奖源码 编辑:程序博客网 时间:2024/04/28 00:00
- procedure TDpModel.ServiceNames(Names: TStrings; DisplayNames: TStrings = nil;
- const Service_Type: integer = $30; const Computer: PChar = nil);
- {
- 返回系统服务列表,Names:用于接收返回的服务名称列表,
- DisplayName:用于接收返回的对应显示名称列表,
- uType:需要返回那些类型服务名称列表,可以为SERVICE_DRIVER,SERVICE_WIN32,SERVICE_ALL
- }
- type
- TEnumServices = array[0..0] of TEnumServiceStatus; //windows API结构体
- PEnumServices = ^TEnumServices; //声明类指针
- var
- SCM: SC_Handle;
- Services: PEnumServices; //定义结构体
- Len: Cardinal; //无符号32位整数 ,取值0到4294967295范围。
- ServiceCount, ResumeHandle, i: Cardinal;
- begin
- ResumeHandle := 0;
- //建立了一个连接到服务控制管理器的句柄,并打开指定的数据库。
- SCM := OpenSCManager(Computer, nil, SC_MANAGER_ALL_ACCESS);
- {
- Computer:计算机标示指针,如果该指针为NULL ,或者如果它指向一个空字符串,
- 则连接到本地计算机上的服务控制管理器。
- nil:如果该指针为NULL ,默认打开ServicesActive数据库。
- SC_MANAGER_ALL_ACCESS:指定访问服务的权限。
- }
- Len := 0;
- ServiceCount := 0;
- Services := nil;
- try
- Names.BeginUpdate;
- //判断DisplayNames是否为空
- if Assigned(DisplayNames) then DisplayNames.BeginUpdate;
- if SCM <> 0 then
- begin
- //枚举当前系统服务,详见MSDN
- EnumServicesStatus(SCM, SERVICE_DRIVER or SERVICE_WIN32, SERVICE_STATE_ALL,
- Services[0], 0, Len, ServiceCount, ResumeHandle);
- GetMem(Services, Len);
- EnumServicesStatus(SCM, SERVICE_DRIVER or SERVICE_WIN32, SERVICE_STATE_ALL,
- Services[0], Len, Len, ServiceCount, ResumeHandle);
- //Tstring赋值
- Names.Add(IntToStr(ServiceCount));
- //循环遍历服务
- for i := 0 to ServiceCount - 1 do
- begin
- Names.Add(Services[i].lpServiceName);
- if Assigned(DisplayNames) then
- begin
- DisplayNames.Add(Services[i].lpDisplayName);
- end;
- end;
- FreeMem(Services);
- end;
- finally
- Names.EndUpdate;
- if Assigned(DisplayNames) then DisplayNames.EndUpdate;
- CloseServiceHandle(SCM);
- end;
- end;
0 0
- Delphi如何获取系统服务(即Service服务程序)列表
- Delphi如何获取系统服务(即Service服务程序)列表
- 获取系统服务列表
- 如何不用Delphi提供的ServiceApp写系统服务程序
- delphi服务程序(service)的调试方法
- 用 Delphi 创建服务程序(Service)
- 用 Delphi 创建服务程序(Service)
- delphi服务程序(service)的调试方法
- Delphi编写系统服务四:如何限制系统服务和桌面程序只运行一个
- Delphi编写系统服务四:如何限制系统服务和桌面程序只运行一个
- Delphi编写系统服务一:如何编写一个系统服务
- Delphi编写系统服务一:如何编写一个系统服务
- Delphi编写Windows系统服务程序【转帖】
- 用 Delphi 创建系统服务程序
- Activity 如何获取到各种服务service
- 如何增加一个系统服务service
- 用Delphi编写Windows服务程序(Winnt Service Application)
- delphi创建具有托盘的服务程序(service)
- Delphi中控制VBA 宏
- SEEM: simulation experimental environments for mobile applications in MANETs: poster
- Delphi 与 Word_VBA
- 事件处理程序
- TD-SCDMA系统外的干扰以及邻道泄漏功率
- Delphi如何获取系统服务(即Service服务程序)列表
- Java中类加载过程和对象创建过程
- Delphi中如何调用Excel VBA
- Servlet的学习
- JAVA中的常量定义在class中还是interface中比较合理?
- python3爬虫之旅
- HDU-2870-Largest Submatrix(DP)
- 整数转16进制字符串,不用系统函数
- JDK + eclipse mars + CDT + PyDev