8 years ago
PropertySource - Windows Services
WARNING - This propertysource pulls a list of all Windows services installed. This does not filter the services to only show running or auto-starting services. Useful for auditing, auto-grouping,...
This is really useful Brandon, thanks. I was only interested in the Running state services and I wanted the list sorted on the service's caption in the MSC console, so I modified the code slightly:
import com.santaba.agent.groovyapi.win32.WMI;
def hostname = hostProps.get("system.hostname");
def wmiQuery = " SELECT Name, Caption, State, Status FROM Win32_Service WHERE State='RUNNING' ";
def session = WMI.open(hostname);
def result = session.queryAll("CIMv2", wmiQuery, 15);
def runningServicesList = result.CAPTION.sort();
def winServicesRunning = runningServicesList.toString().replaceAll(",", " | ");
println "WinServicesRunning=" + winServicesRunning;