SecurityIdentifier Class
- Supported on windows5.1.2600
Represents a security identifier (SID) that uniquely identifies a user, group, or other security principal.
[SupportedOSPlatform("windows5.1.2600")]
public sealed class SecurityIdentifier : IEquatable<SecurityIdentifier?>Remarks
A SID is a variable-length structure that uniquely identifies a security principal in Windows. This class provides methods to resolve SIDs to account names and domains.
Example
// Get a well-known SID
var adminSid = SecurityIdentifier.FromWellKnown(WellKnownSidType.WinBuiltinAdministratorsSid);
Assert.Equal("S-1-5-32-544", adminSid.Sid);
// The account name is localized: "BUILTIN\Administrators" on an English version of Windows
Assert.NotEmpty(adminSid.FullName);
// Compare SIDs
using var token = AccessToken.OpenCurrentProcessToken(TokenAccessLevels.Query);
var ownerSid = token.GetOwner();
if (ownerSid == adminSid)
{
// The owner is the Administrators group, which is the case of an elevated process
}- Implements
Properties
| Name | Description |
|---|---|
| Domain | Gets the domain name associated with the SID. |
| FullName | Gets the full name in the format "Domain\Name". |
| Name | Gets the account name associated with the SID. |
| Sid | Gets the string representation of the SID (e.g., "S-1-5-21-..."). |
Domain
SecurityIdentifier.csGets the domain name associated with the SID.
public string? Domain { get; }Property value
string? The domain name, or null if the SID could not be resolved.
Exceptions
Win32Exception- The account lookup failed.
Remarks
Resolved on first access, which may query the local security authority or a domain controller.
FullName
SecurityIdentifier.csGets the account name associated with the SID.
public string? Name { get; }Property value
string? The account name, or null if the SID could not be resolved.
Exceptions
Win32Exception- The account lookup failed.
Remarks
Resolved on first access, which may query the local security authority or a domain controller.
Methods
| Name | Description |
|---|---|
| Equals(SecurityIdentifier?) | Determines whether the specified SecurityIdentifier is equal to the current instance. |
| Equals(object?) | Determines whether the specified object is equal to the current object. |
| FromWellKnown(WellKnownSidType) | Creates a SecurityIdentifier for a well-known SID type. |
| GetHashCode() | Serves as the default hash function. |
| ToString() | Returns a string representation of the security identifier. |
Equals overloads
Equals(SecurityIdentifier?)
SecurityIdentifier.csDetermines whether the specified SecurityIdentifier is equal to the current instance.
public bool Equals(SecurityIdentifier? other)Equals(object?)
SecurityIdentifier.csFromWellKnown(WellKnownSidType)
SecurityIdentifier.csCreates a SecurityIdentifier for a well-known SID type.
public static SecurityIdentifier FromWellKnown(WellKnownSidType type)Parameters
typeWellKnownSidType- The well-known SID type to create.
Returns
SecurityIdentifier A SecurityIdentifier representing the well-known SID.
Exceptions
Win32Exception- The SID could not be created.
Example
var adminSid = SecurityIdentifier.FromWellKnown(WellKnownSidType.WinBuiltinAdministratorsSid);
var systemSid = SecurityIdentifier.FromWellKnown(WellKnownSidType.WinLocalSystemSid);
Assert.Equal("S-1-5-32-544", adminSid.Sid);
Assert.Equal("S-1-5-18", systemSid.Sid);GetHashCode()
SecurityIdentifier.csToString()
SecurityIdentifier.csOperators
| Name | Description |
|---|---|
| operator ==(SecurityIdentifier?, SecurityIdentifier?) | |
| operator !=(SecurityIdentifier?, SecurityIdentifier?) |
operator ==(SecurityIdentifier?, SecurityIdentifier?)
SecurityIdentifier.cspublic static bool operator ==(SecurityIdentifier? left, SecurityIdentifier? right)No documentation is available.
operator !=(SecurityIdentifier?, SecurityIdentifier?)
SecurityIdentifier.cspublic static bool operator !=(SecurityIdentifier? left, SecurityIdentifier? right)No documentation is available.