show all FileSystemRights with C#

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i have read internet and publish manuals.

i'm not able to get FileSystemRighs in C# to present to me all the
permissions so that i can display, capture and compare. when i do a
console.writeline({0}, rule.FileSystemRighs); i get a simple line:
Read&Execute.

yet if i step through the code i will get maybe 4 or more values. so the
question is how do i work with FileSystemRights to capture the complete
permissions string for me to do what ever to?

here is a sample of code:
static void PrintACE(FileSystemAccessRule rule)
{
Console.WriteLine("{0} {1} to {2} ({3})",
AccessControlType.Allow == rule.AccessControlType ? "Grant"
: "Deny",
rule.FileSystemRights,
rule.IdentityReference,
rule.IsInherited ? "Inherited" : "Direct");
}

here is the output of one user:
ReadAndExecute, Synchronize

what i see in debug mode:
rule.FileSystemRights = ReadData | ReadExtendedAttributes | ExecuteFile |
ReadAttributes | ReadPermissions | Synchronize

thanks.
herb
 
auldh said:
i have read internet and publish manuals.

i'm not able to get FileSystemRighs in C# to present to me all the
permissions so that i can display, capture and compare. when i do a
console.writeline({0}, rule.FileSystemRighs); i get a simple line:
Read&Execute.

yet if i step through the code i will get maybe 4 or more values. so the
question is how do i work with FileSystemRights to capture the complete
permissions string for me to do what ever to?

here is a sample of code:
static void PrintACE(FileSystemAccessRule rule)
{
Console.WriteLine("{0} {1} to {2} ({3})",
AccessControlType.Allow == rule.AccessControlType ? "Grant"
: "Deny",
rule.FileSystemRights,
rule.IdentityReference,
rule.IsInherited ? "Inherited" : "Direct");
}

here is the output of one user:
ReadAndExecute, Synchronize

what i see in debug mode:
rule.FileSystemRights = ReadData | ReadExtendedAttributes | ExecuteFile |
ReadAttributes | ReadPermissions | Synchronize

thanks.
herb


ReadAndExecute is the "unification" of a couple of other accessrights
(ReadData, ReadExtendedAttributes,| ExecuteFile, ReadAttributes and
ReadPermissions ), take a look at the FileSystemRights enum you'll
understand which ones.

If you need each individual right from the FileSystemRights value then
you'll have to parse the value back into it's individual values.

Willy.
 
Willy,
that is what i want to do. is that a matter or running it throught
"switch/case" what is the best way to parse it correctly?

i see tons of inputs about how to modify, add and delete but nothing to
iterate the output of FileSystemRights. can you help?
 
If you really need to parse all individual bits you'll have to loop through
the enum values, sure there are different ways to do this, following
illustrates one possibility:

static void PrintACE(FileSystemAccessRule rule)
{
foreach (string right in Enum.GetNames(typeof(FileSystemRights)))
{
int val = Convert.ToInt32(Enum.Parse(typeof(FileSystemRights), right));
// remove combined values
if((val != 0x1f01ff) && (val != 0x301bf) && (val != 0x20089) && (val !=
0x200a9) && (val != 0x116))
{
if(((int)rule.FileSystemRights & val) > 0)
Console.WriteLine("{0} ", right);
}
}
}

Willy.
 
Willy,
this is absolutely brilliant. simple and clean.
i did not see anything like this anywhere.

what do you use for a reference guide on this windows security stuff. i
picked up Keith Brown's "Programming windows security" and "the .NET
developer's guide to Windows security". it missed this type of detail.

thank you very.
 
Back
Top