コード例 #1
0
ファイル: SchTasks.cs プロジェクト: WoodyPhil/wincompose
        private static string GetLocalUserGroupName()
        {
            var user_name   = new StringBuilder();
            var domain_name = new StringBuilder();

            user_name.EnsureCapacity(128);
            domain_name.EnsureCapacity(128);
            var user_size   = (uint)user_name.Capacity;
            var domain_size = (uint)domain_name.Capacity;

            // Build SID S-1-5-32-545 (“Users” group)
            byte[] sid = new byte[]
            {
                1,                // Revision
                2,                // SubAuthorityCount
                0, 0, 0, 0, 0, 5, // IdentifierAuthority = SECURITY_NT_AUTHORITY (5)
                32, 0, 0, 0,      // SECURITY_BUILTIN_DOMAIN_RID (32)
                33, 2, 0, 0,      // DOMAIN_ALIAS_RID_USERS (545)
            };

            if (!NativeMethods.LookupAccountSid(null, sid, user_name, ref user_size, domain_name,
                                                ref domain_size, out SID_NAME_USE sid_use))
            {
                return(@"BUILTIN\Users");
            }

            return($@"{domain_name}\{user_name}");
        }