如何在 uwp(Windows 10)中获取当前登录用户的组信息(如来宾、管理员等)? [英] how to get group info(like guest,admin..etc) of current login user in uwp (windows 10)?

查看:34
本文介绍了如何在 uwp(Windows 10)中获取当前登录用户的组信息(如来宾、管理员等)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 UWP(windows 10) 中获取属于当前用户的组名?

I want to get the Group name that belongs to current user in UWP(windows 10)?

我点击以下链接:

https://msdn.microsoft.com/en-us/library/windows/apps/windows.system.knownuserproperties.aspx

在 Windows 中获取用户名10 C# UWP 通用 Windows 应用程序

但它不能帮助我找到组名.

But it does not help me find group name.

如果在 c# 中可能,请提供建议或链接..

if it is possible in c# plz give suggestion or links..

推荐答案

您可以从 用户类

恐怕您无法获取用户角色.UWP 应用程序是沙盒的,系统功能不可用.如果您需要它们,您可以通过以下方式创建 .Net 应用程序:

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
        }

这篇关于如何在 uwp(Windows 10)中获取当前登录用户的组信息(如来宾、管理员等)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆