Autor Beitrag
Metrik
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 80

Win XP, Win Vista
C# (VS 2003, #Develop)
BeitragVerfasst: Mo 23.10.06 17:37 
Hallo
Ich möchte das etwa wie folgt lösen, nur funktioniert das nicht.
Kann mir wer zeigen, was ich falsch mache oder wie man es besser lösen könnte

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
    private static string getRole()
    {
        string role = String.Empty;

        AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
        WindowsPrincipal windowsPrincipal = (Thread.CurrentPrincipal as WindowsPrincipal);

        try
        {
            switch (windowsPrincipal.IsInRole)
            {
                case WindowsBuiltInRole.Administrator:
                    role = "Admin";
                    break;
                case WindowsBuiltInRole.User:
                    role = "User";
                    break;
            }

        }
        catch (Exception exception)
        {
               Console.WriteLine(exception.Message);
        }    
 
        return role;


Danke
Metrik
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mo 23.10.06 17:50 
Ich habe nicht den Eindruck, dass Du Dir auch nur einmal die Doku zu "IsInRole" angesehen hast. Bzw. hätte schon das Lesen der Compilermeldung geholfen.
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
            if (windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator))
                return "Admin";

            if (windowsPrincipal.IsInRole(WindowsBuiltInRole.Guest))
                return "Gast";

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".