// Based off of code by Lee Christensen(@tifkin_) from https://github.com/Invoke-IR/ACE/blob/master/ACE-Management/PS-ACE/Scripts/ACE_Get-NetworkConnection.ps1#L1046 public static string?GetServiceNameFromTag(uint processId, uint serviceTag) { var serviceTagQuery = new SC_SERVICE_TAG_QUERY { ProcessId = processId, ServiceTag = serviceTag }; var res = I_QueryTagInformation(IntPtr.Zero, SC_SERVICE_TAG_QUERY_TYPE.ServiceNameFromTagInformation, ref serviceTagQuery); return(res == Win32Error.Success ? Marshal.PtrToStringUni(serviceTagQuery.Buffer) : null); }
public static extern uint I_QueryTagInformation( IntPtr Unknown, SC_SERVICE_TAG_QUERY_TYPE Type, ref SC_SERVICE_TAG_QUERY Query );