问题
I want to get the Group name that belongs to current user in UWP(windows 10)?
i follow the links below:
https://msdn.microsoft.com/en-us/library/windows/apps/windows.system.knownuserproperties.aspx
Get UserName in a Windows 10 C# UWP Universal Windows app
But it does not help me find group name.
if it is possible in c# plz give suggestion or links..
回答1:
You can get user information from User class
I am afraid that you can't get roles of user. UWP applications are sandboxed and system features are not available from them. If you need them you can create .Net application this way:
// list all groups
foreach (var u in System.Security.Principal.WindowsIdentity.GetCurrent().Groups)
{
Console.WriteLine("{0} ", u.Value);
}
// check is user in group
System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(System.Security.Principal.WindowsIdentity.GetCurrent());
if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator))
{
// do what you want
}
来源:https://stackoverflow.com/questions/36713824/how-to-get-group-infolike-guest-admin-etc-of-current-login-user-in-uwp-windo