how to get group info(like guest,admin..etc) of current login user in uwp (windows 10)?

纵然是瞬间 提交于 2019-12-25 07:46:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!