码迷,mamicode.com
首页 > 其他好文 > 详细

系统服务

时间:2014-07-29 12:51:26      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:api   delphi   系统服务   

function StopServies(sServiceName: String): boolean; // 停止某个服务;
var
  schService: SC_HANDLE;
  schSCManager: SC_HANDLE;
  ssStatus: TServiceStatus;
begin
  schSCManager := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS);
  schService := OpenService(schSCManager, Pchar(sServiceName), SERVICE_ALL_ACCESS);
  try
    if ControlService(schService, SERVICE_CONTROL_STOP, ssStatus) then
    begin
      Sleep(1000);
      while (QueryServiceStatus(schService, ssStatus)) do
      begin
        Application.ProcessMessages;
        if ssStatus.dwCurrentState = SERVICE_STOP_PENDING then Sleep(1000)
        else break;
      end; // while
      if ssStatus.dwCurrentState = SERVICE_STOPPED then result := True
      else result := False;
    end
    else result := False;
  finally
    CloseServiceHandle(schService);
    CloseServiceHandle(schSCManager);
  end;
end;

系统服务,布布扣,bubuko.com

系统服务

标签:api   delphi   系统服务   

原文地址:http://blog.csdn.net/gfuchao/article/details/38264827

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!