static IEnumerable <ServiceTriggerInformation> GetTriggersForService(SafeServiceHandle service) { List <ServiceTriggerInformation> triggers = new List <ServiceTriggerInformation>(); using (var buf = new SafeStructureInOutBuffer <SERVICE_TRIGGER_INFO>(8192, false)) { int required = 0; if (!QueryServiceConfig2(service, SERVICE_CONFIG_TRIGGER_INFO, buf, 8192, out required)) { return(triggers.AsReadOnly()); } SERVICE_TRIGGER_INFO trigger_info = buf.Result; if (trigger_info.cTriggers == 0) { return(triggers.AsReadOnly()); } SERVICE_TRIGGER[] trigger_arr; using (SafeHGlobalBuffer trigger_buffer = new SafeHGlobalBuffer(trigger_info.pTriggers, trigger_info.cTriggers * Marshal.SizeOf(typeof(SERVICE_TRIGGER)), false)) { trigger_arr = new SERVICE_TRIGGER[trigger_info.cTriggers]; trigger_buffer.ReadArray(0, trigger_arr, 0, trigger_arr.Length); } for (int i = 0; i < trigger_arr.Length; ++i) { triggers.Add(new ServiceTriggerInformation(trigger_arr[i])); } return(triggers.AsReadOnly()); } }
internal ServiceTriggerInformation(SERVICE_TRIGGER trigger) { TriggerType = trigger.dwTriggerType; Action = trigger.dwAction; SubType = trigger.GetSubType(); SubTypeDescription = GetSubTypeDescription(); List <ServiceTriggerCustomData> data = new List <ServiceTriggerCustomData>(); if (trigger.pDataItems != IntPtr.Zero && trigger.cDataItems > 0) { SERVICE_TRIGGER_SPECIFIC_DATA_ITEM[] data_items; ReadArray(trigger.pDataItems, trigger.cDataItems, out data_items); for (int i = 0; i < data_items.Length; ++i) { data.Add(new ServiceTriggerCustomData(data_items[i])); } } CustomData = data.AsReadOnly(); }