/// <summary> /// Gets the kernel object type-names array. Use SYSTEM_HANDLE_TABLE_ENTRY_INFO_EX.ObjectTypeIndex as index for the returned array to retrieve the type-name. /// </summary> /// <returns></returns> /// <remarks> /// Object-type "Directory" does not mean a file-system folder! It refers to a Directory for Kernel-Objects. /// </remarks> public static string[] GetObjectTypeNames() { var objectTypes = KernelObject.EnumerateAllObjectTypes(); string[] objectTypesArr = Enumerable.Repeat("<unknown>", 2) // not sure why we need this offset - was determined through experiments .Concat(objectTypes.Select(item => item.TypeName)).ToArray(); return(objectTypesArr); }
public ObjectTypeFilter(IEnumerable <string> objectTypeNames) { if (objectTypeNames == null) { throw new ArgumentNullException(nameof(objectTypeNames), $"{nameof(objectTypeNames)} is null."); } string[] allObjectTypesArr = KernelObject.GetObjectTypeNames(); _objectTypeIndices = objectTypeNames.Select(item => FindTypeIndex(item, allObjectTypesArr)).ToArray(); }
/// <summary> /// Gets the process-Ids of the processes that are using the specified file or serial-port. /// </summary> /// <param name="path">The path (e.g. 'c:\somefolder\somefile.txt' or 'COM1').</param> /// <returns></returns> public IEnumerable <int> GetProcessIdUsingPath(string path) { ObjectTypeFilter fileTypeFilter = new ObjectTypeFilter("File"); IEnumerable <int> processIds = KernelObject.EnumerateAllObjects() .Where(fileTypeFilter.IsMatch) .Select(info => Tuple.Create(info.UniqueProcessId, GetDevicePathFromInfo(info))) .Where(item => !string.IsNullOrEmpty(item.Item2)) .Select(item => Tuple.Create(item.Item1, DevicePathConverter.ConvertDevicePathToDosPath(item.Item2))) .Where(item => item.Item2 == path) .Select(item => item.Item1); return(processIds); }