本文整理汇总了C#中System.Security.Principal.SecurityIdentifier.IsAccountSid方法的典型用法代码示例。如果您正苦于以下问题:C# SecurityIdentifier.IsAccountSid方法的具体用法?C# SecurityIdentifier.IsAccountSid怎么用?C# SecurityIdentifier.IsAccountSid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Principal.SecurityIdentifier
的用法示例。
在下文中一共展示了SecurityIdentifier.IsAccountSid方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AreSidsInSameDomain
internal static bool AreSidsInSameDomain(SecurityIdentifier sid1, SecurityIdentifier sid2)
{
if (!sid1.IsAccountSid() || !sid2.IsAccountSid())
{
return false;
}
else
{
return sid1.AccountDomainSid.Equals(sid2.AccountDomainSid);
}
}
示例2: GetUpnFromSelection
private string GetUpnFromSelection(UnsafeNativeMethods.DsSelection selection)
{
if (!string.IsNullOrEmpty(selection.pwzUPN))
{
return selection.pwzUPN;
}
const string sidPropertyName = "objectSid";
string upn = selection.pwzADsPath;
// Try to get the UPN value from AD path
try
{
using (DirectoryEntry entry = new DirectoryEntry(upn))
{
if (entry.Properties.Contains(sidPropertyName))
{
SecurityIdentifier sid = new SecurityIdentifier((byte[])entry.Properties[sidPropertyName].Value, 0);
if (sid.IsAccountSid())
{
NTAccount acc = (NTAccount)sid.Translate(typeof(NTAccount));
upn = acc.Value;
}
}
}
}
catch (Exception e)
{
Trace.TraceError(e.Message);
}
return upn;
}
示例3: Main
static void Main(string[] args)
{
// domainSid: WindowsIdentity.GetCurrent().User.AccountDomainSid);
if (args.Length > 0)
{
if (args[0].StartsWith("-?") ||
args[0].StartsWith("-h") ||
args[0].StartsWith("-help") ||
args[0].StartsWith("/?") ||
args[0].StartsWith("/h") ||
args[0].StartsWith("/help"))
{
ShowHelp();
}
else if (Enum.IsDefined(typeof(WellKnownSidType), args[0]))
{
try
{
WellKnownSidType sidType = (WellKnownSidType)Enum.Parse(typeof(WellKnownSidType), args[0], false);
SecurityIdentifier sid = null;
if (args[0].StartsWith("Account"))
{
sid = new SecurityIdentifier(sidType, WindowsIdentity.GetCurrent().User.AccountDomainSid);
}
else
{
sid = new SecurityIdentifier(sidType, null);
}
NTAccount NTUser = (NTAccount)sid.Translate(typeof(System.Security.Principal.NTAccount));
Console.WriteLine("[" + sidType.ToString() + "]");
Console.WriteLine("Name=" + NTUser.ToString());
Console.WriteLine("Shortname=" + NTUser.ToString().Substring(NTUser.ToString().IndexOf("\\")+1));
Console.WriteLine("SID=" + sid.ToString());
Console.WriteLine("IsAccountSid=" + sid.IsAccountSid().ToString().ToUpper());
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
else
{
if (args[0].StartsWith("S-"))
{
try
{
SecurityIdentifier sid = new SecurityIdentifier(args[0]);
NTAccount NTUser = (NTAccount)sid.Translate(typeof(System.Security.Principal.NTAccount));
Console.WriteLine("[" + sid.ToString() + "]");
Console.WriteLine("Name=" + NTUser.ToString());
Console.WriteLine("Shortname=" + NTUser.ToString().Substring(NTUser.ToString().IndexOf("\\") + 1));
Console.WriteLine("SID=" + sid.ToString());
Console.WriteLine("IsAccountSid=" + sid.IsAccountSid().ToString().ToUpper());
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
else
{
try
{
NTAccount NTUser = new NTAccount(args[0]);
SecurityIdentifier sid = (SecurityIdentifier)NTUser.Translate(typeof(SecurityIdentifier));
Console.WriteLine("[" + NTUser.ToString() + "]");
Console.WriteLine("Name=" + NTUser.ToString());
Console.WriteLine("Shortname=" + NTUser.ToString().Substring(NTUser.ToString().IndexOf("\\") + 1));
Console.WriteLine("SID=" + sid.ToString());
Console.WriteLine("IsAccountSid=" + sid.IsAccountSid().ToString().ToUpper());
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
else
{
ShowHelp();
}
}