Geeks With Blogs
Tex-blog Mobile and other stuff
Charter 12 lesson 2 gives in its Lab a sample code that will not work on everyones computer. The problem is with the Guest account name that is in English, which will not work on systems in different languages, like mine for example. Below code:

DirectorySecurity ds = new DirectorySecurity();
string gname = "Guest";

ds.AddAccessRule(new FileSystemAccessRule(gname,
    FileSystemRights.Read, AccessControlType.Allow)); // Exception!

Directory.CreateDirectory(@"C:\Guest", ds);
File.Create(@"C:\Guest\Data.data");

Throws IdentityNotMappedException, to correct this use below code to get Guest user account name from SID value:

SecurityIdentifier guestSid = new SecurityIdentifier(
 
  WellKnownSidType.BuiltinGuestsSid, null);

NTAccount guser = (NTAccount)guestSid.Translate(typeof(NTAccount));
gname = guser.ToString();

This brings an interesting topic (not covered by Training Kit) on what actually are SID’s. These are a numerical representations of user account name – which in .NET is being encapsulated by NTAccount class. SID’s are encapsulated by SecurityIdentifier class. You can convert (or translate) between those two. Very interesting article on this topic can be found in “The .NET Developer's Guide to Windows Security” by Keith Brown:

http://www.pluralsight.com/wiki/default.aspx/Keith.GuideBook/WhatIsASID.html

and

http://www.pluralsight.com/wiki/default.aspx/Keith.GuideBook/HowToProgramWithSIDs.html

Posted on Tuesday, September 11, 2007 6:02 PM 70-536 preparation | Back to top


Comments on this post: Language independent user account naming (Ch12)

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Martinez | Powered by: GeeksWithBlogs.net