public static byte GetSidSubAuthorityCount(PSID pSid) { var ptr = InternalGetSidSubAuthorityCount(pSid); Win32Error.GetLastError().ThrowIfFailed(); return(Marshal.ReadByte(ptr)); }
public static uint GetSidSubAuthority(PSID pSid, uint nSubAuthority) { var ptr = InternalGetSidSubAuthority(pSid, nSubAuthority); Win32Error.GetLastError().ThrowIfFailed(); return(unchecked ((uint)Marshal.ReadInt32(ptr))); }
public static bool QueryServiceConfig2 <T>(IntPtr hService, ServiceConfigOption dwInfoLevel, out T configInfo) { var b = QueryServiceConfig2(hService, dwInfoLevel, IntPtr.Zero, 0, out uint size); configInfo = default(T); if (!b && Win32Error.GetLastError() != Win32Error.ERROR_INSUFFICIENT_BUFFER) { return(false); } if (size < Marshal.SizeOf(typeof(T))) { throw new ArgumentException("Type mismatch", nameof(configInfo)); } using (var buf = new SafeHGlobalHandle((int)size)) { if (!QueryServiceConfig2(hService, dwInfoLevel, (IntPtr)buf, size, out size)) { return(false); } configInfo = buf.ToStructure <T>(); } return(true); }
/// <summary>Converts a bool to a Win32Error.</summary> /// <param name="result">Result state.</param> /// <returns>Resulting error or <see cref="Win32Error.ERROR_SUCCESS"/> on success.</returns> public static Win32Error BoolToLastErr(bool result) => result ? Win32Error.ERROR_SUCCESS : Win32Error.GetLastError();