本文整理汇总了C#中System.Security.Principal.NTAccount.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# NTAccount.ToString方法的具体用法?C# NTAccount.ToString怎么用?C# NTAccount.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Principal.NTAccount
的用法示例。
在下文中一共展示了NTAccount.ToString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
}
示例2: GrantRegistryAccess
private static void GrantRegistryAccess(string key, Prison prison)
{
NTAccount account = new NTAccount(null, prison.User.Username);
var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
using (RegistryKey rk = hklm.OpenSubKey(key, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.FullControl))
{
RegistrySecurity rs = rk.GetAccessControl();
RegistryAccessRule rar = new RegistryAccessRule(
account.ToString(),
RegistryRights.FullControl,
InheritanceFlags.ContainerInherit,
PropagationFlags.None,
AccessControlType.Allow);
rs.AddAccessRule(rar);
rk.SetAccessControl(rs);
}
}