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).
if (sid.StartsWith("S-1-5-21") && sid.EndsWith("-501"))
{
return "Guest";
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));