Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在uwp(windows 10)中获取当前登录用户的组信息(如来宾、管理员等)?_C#_Wpf_Winforms_Xaml_Win Universal App - Fatal编程技术网

C# 如何在uwp(windows 10)中获取当前登录用户的组信息(如来宾、管理员等)?

C# 如何在uwp(windows 10)中获取当前登录用户的组信息(如来宾、管理员等)?,c#,wpf,winforms,xaml,win-universal-app,C#,Wpf,Winforms,Xaml,Win Universal App,我想在UWP(windows 10)中获取属于当前用户的组名 以下是我的链接: 但它不能帮助我找到组名 如果可能,请在c#中给出建议或链接。您可以从 恐怕您无法获得用户的角色。UWP应用程序是沙盒式的,系统功能不可用。如果需要,可以通过以下方式创建.Net应用程序: // list all groups foreach (var u in System.Security.Principal.WindowsIdentity.GetCurrent().G

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

以下是我的链接:

但它不能帮助我找到组名


如果可能,请在c#中给出建议或链接。

您可以从

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

            // 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应用程序是沙盒式的,系统功能不可用。如果需要,可以通过以下方式创建.Net应用程序:

            // 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
        }

对不起,亚历克斯,我不是在问工作组。我要求该组属于当前用户,如(管理员、来宾…)。无论如何,谢谢你的回复。对不起,亚历克斯,我不是在问工作组。我要求该组属于当前用户,如(管理员、来宾…)。无论如何,谢谢你的回复。谢谢…你能给我一些关于.net应用程序的简单链接,这样我就可以在代理组件中使用它了。谢谢…你能给我一些关于.net应用程序的简单链接,这样我就可以在代理组件中使用它了。