各位高手:
    能用delphi编程实现,检测windows automatic update及background intelligent transfer service是否开启 ,并且如果开启设为禁用吗?或者用Delphi能够用的API?

解决方案 »

  1.   

    //获取服务状态
    uses
      WinSvc;    //引用此单元
     
    function GetServiceStatusString(sServiceName: string): string;
    var
      hService, hSCManager: SC_HANDLE;
      SS: TServiceStatus;
    begin
      hSCManager := OpenSCManager(nil, SERVICES_ACTIVE_DATABASE, SC_MANAGER_CONNECT);
      if hSCManager = 0 then
      begin
        result := 'Can not open the service control manager';
        exit;
      end;
      hService := OpenService(hSCManager, PChar(sServiceName), SERVICE_QUERY_STATUS);
      if hService = 0 then
      begin
        CloseServiceHandle(hSCManager);
        result := 'Can not open the service(' + sServiceName + ')';
        exit;
      end;
      if not QueryServiceStatus(hService, SS) then
        result := 'Can not query the service status'
      else
      begin
        case SS.dwCurrentState of
          SERVICE_CONTINUE_PENDING:
            result := 'The service(' + sServiceName + ') continue is pending';
          SERVICE_PAUSE_PENDING:
            result := 'The service(' + sServiceName + ') pause is pending.';
          SERVICE_PAUSED:
            result := 'The service(' + sServiceName + ') is paused.';
          SERVICE_RUNNING:
            result := 'The service(' + sServiceName + ') is running.';
          SERVICE_START_PENDING:
            result := 'The service(' + sServiceName + ') is starting.';
          SERVICE_STOP_PENDING:
            result := 'The service(' + sServiceName + ') is stopping.';
          SERVICE_STOPPED:
            result := 'The service(' + sServiceName + ') is not running.';
        else
          result := 'Unknown Status';
        end;
      end;
      CloseServiceHandle(hSCManager);
      CloseServiceHandle(hService);
    end;
    停止服务的代码这里有 http://www.xxlinux.com/linux/dev/Delphi/2007-11-01/11462.html
    自动更新是禁用 Automatic Updates服务就可以了。
      

  2.   

    注册表信息保存在
    HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate
    下面,直接改就好了
      

  3.   

     辛苦辛苦~
    hService := OpenService(hSCManager, PChar(sServiceName), SERVICE_QUERY_STATUS);
    运行这里,无法打开服务,传递Automatic Updates不行,WindowsUpdate也不行,是我写的字符串不对吗