您的位置:首页 > 产品设计 > UI/UE

How can I get the local group name for guests/administrators?

2011-11-15 16:36 351 查看
The names of groups are localised depending on system language.

For 'well known' groups like 'Administrators' and 'Guests' you should retrieve based on the SID. The SID for Guests is:

S-1-5-32-546

There is a list of well known SIDs here:
http://support.microsoft.com/kb/243330
Looking up the account by SID is the best way to go. It's a bit contrived, but the way it works is this:

The Administrator account's SID always starts with S-1-5-21 and ends with -500. Everything else in-between is random (the domain's SID).

The Guest account's SID always starts with S-1-5-21 and ends with -501.

System.Security.Principal.WindowsIdentity currentUser = System.Security.Principal.WindowsIdentity.GetCurrent();

var sid = currentUser.User.ToString().ToUpper();

if (sid.StartsWith("S-1-5-21") && sid.EndsWith("-501"))

{

return "Guest";

}

WindowsPrincipal wp =

new WindowsPrincipal(currentUser);

Console.WriteLine(wp.IsInRole(

WindowsBuiltInRole.Guest));

Console.WriteLine(wp.IsInRole(

WindowsBuiltInRole.Administrator));

Console.WriteLine(wp.IsInRole(

WindowsBuiltInRole.PowerUser));
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: