# Copyright 2026 SigmaSRC, Inc. All Rights Reserved.

"""Gather script for getting service info."""


import os
import logging
from win32com.client import GetObject

logger = logging.getLogger("gather.gather_service")

def Gather(collector):
    # write header to output
    table = collector.table("service", ["servicename", "servicestate"])
    try:
        services = GetObject("WinMgMts://./root/cimv2").InstancesOf("Win32_Service")
        for service in services:
            name = service.Properties_("Name").Value
            state = service.Properties_("State").Value
            table.add((name, state))
    except:
        logger.exception("service gather failed")

def _test():
    from sigma.gather import gathering
    gathering.test(Gather)

if __name__ == "__main__":
    _test()
