/* * Process Hacker - * windows SID wrapper * * Copyright (C) 2008 wj32 * * This file is part of Process Hacker. * * Process Hacker is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Process Hacker is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Process Hacker. If not, see . */ using System; using System.Runtime.InteropServices; using System.Security.Principal; namespace ProcessHacker { /// /// Represents a Windows security identifier. /// public class WindowsSID { private SecurityIdentifier _id; private string _name; private string _nameNoDomain; /// /// Creates a new WindowsSID instance, specifying a pointer to a SID. /// /// A pointer to a SID. public WindowsSID(int SID) { _id = new SecurityIdentifier(new IntPtr(SID)); _name = Win32.GetAccountName(SID, true); _nameNoDomain = Win32.GetAccountName(SID, false); } /// /// Gets the name of the user or group which corresponds with this SID. /// /// Specifies whether the domain is to be included in the name. /// A string. public string GetName(bool IncludeDomain) { if (IncludeDomain) return _name; else return _nameNoDomain; } /// /// Gets a SecurityIdentifier instance. /// public SecurityIdentifier GetSecurityIdentifier() { return _id; } /// /// Gets the SID's value using Security Descriptor Definition Language (SDDL). /// /// A string. public string GetStringSID() { return _id.ToString(); } } }