public static Boolean TryQuerySystemInformation(SystemInfomationClass infoClass, out AllocatedMemoryHandle infoHandle, Int32 startSize = 0) { infoHandle = new AllocatedMemoryHandle(startSize); var info = NtQuerySystemInformation(infoClass, infoHandle.DangerousGetHandle(), infoHandle.Size, out var actualSize); while (info == NtStatus.InfoLengthMismatch) { infoHandle.ChangeMemorySize(actualSize); info = NativeAPI.NtQuerySystemInformation(infoClass, infoHandle.DangerousGetHandle(), infoHandle.Size, out actualSize); } if (info != NtStatus.Success) { if (infoHandle.IsInvalid) { infoHandle.Close(); } infoHandle = null; return(false); } return(true); }
private static extern NtStatus NtQuerySystemInformation(SystemInfomationClass InfoClass, [Out] IntPtr Info, Int32 Size, out Int32 Length);