Esempio n. 1
0
        public static byte GetSidSubAuthorityCount(PSID pSid)
        {
            var ptr = InternalGetSidSubAuthorityCount(pSid);

            Win32Error.GetLastError().ThrowIfFailed();
            return(Marshal.ReadByte(ptr));
        }
Esempio n. 2
0
        public static uint GetSidSubAuthority(PSID pSid, uint nSubAuthority)
        {
            var ptr = InternalGetSidSubAuthority(pSid, nSubAuthority);

            Win32Error.GetLastError().ThrowIfFailed();
            return(unchecked ((uint)Marshal.ReadInt32(ptr)));
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
 /// <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();