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.
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));
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));
相关文章推荐
- How Can I Get the Unique ID for the Last Inserted Row
- How can I get Maven to stop attempting to check for updates for artifacts from a certain group from maven-central-repo?
- How can I display the chevron for toolbar and open dropdowned popup menu with invisible buttons?
- How can I get the next auto increment value from mssql?
- 数据库-mysql-Can't get hostname for your address
- How to get the MD5 checksum for a file: md5sum, digest, csum, fciv
- Navicat连接数据库Can't get hostname for your address 解决方法
- How To Get English Name For East Asian Font Names
- Navicat连接mysql出现1042错误 Can’t get hostname for your address
- The package NAME needs to be reinstalled, but I can’t find an archive for it
- Mysql 5.5.3 bug:Can't get hostname for your address
- MySQL有关1042 Can’t get hostname for your address的问题分析解决过程
- MYSQL Communication link failure, message from server: "Can't get hostname for your address"
- MySQL:1042 can't get hostname for your address
- How in the world did my (good) name get dragged into this? - 11.01
- How can I get a name of enumerated value
- How can I get the request URL from a Java Filter?
- How to get the MouseEvent coordinates for an element that has CSS3 Transform?
- 继续摘抄:How to fix Apache – “Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName”
- Can't get hostname for your address"错误的解决