Home All Groups Group Topic Archive Search About

Getting the Access Permissions for a specific SID on a File / folder

Author
18 Jul 2006 11:06 AM
Mike Spike
HI all,

How do I go about getting the permmisions of a file.

I have been able to get a list of access control rules and tell if they are
restricting or permiting a permmision but I cant tell which role / right
they are refering to:

I can get this type information by using the fileSystemSecurity object and
pointing it to a file or folder:
---------------------------------
Administrator, allow, inhertited
Users, allow, inhereted
----------------------------------

But what I am aiming for is

---------------------------------
Administrator, allow Full Control, inhertited
Users, allow, read + Modify, inhereted
----------------------------------

I have looked through the classes in the security name space but I am not
sure which class I  need to do this or if the class I am using will work.

Any help would be very welcome or even any external refrences.

By the way I am using VB.Net and the 2.0 framework.

Regards,

Mike

Author
18 Jul 2006 3:02 PM
Dominick Baier
foreach (FileSystemAccessRule rule in security.GetAccessRules(true, true,
typeof(NTAccount)))
            {
                Console.WriteLine("{0} {1} access to {2}",
                    rule.AccessControlType == AccessControlType.Allow ?
                        "grant: " : "deny: ",
                    rule.FileSystemRights,
                    rule.IdentityReference.ToString());
                SecurityIdentifier sid = (SecurityIdentifier)rule.IdentityReference.Translate(typeof(SecurityIdentifier));
                Console.WriteLine(sid.Value);
            }


Show quoteHide quote
> HI all,
>
> How do I go about getting the permmisions of a file.
>
> I have been able to get a list of access control rules and tell if
> they are restricting or permiting a permmision but I cant tell which
> role / right they are refering to:
>
> I can get this type information by using the fileSystemSecurity object
> and
> pointing it to a file or folder:
> ---------------------------------
> Administrator, allow, inhertited
> Users, allow, inhereted
> ----------------------------------
> But what I am aiming for is
>
> ---------------------------------
> Administrator, allow Full Control, inhertited
> Users, allow, read + Modify, inhereted
> ----------------------------------
> I have looked through the classes in the security name space but I am
> not sure which class I  need to do this or if the class I am using
> will work.
>
> Any help would be very welcome or even any external refrences.
>
> By the way I am using VB.Net and the 2.0 framework.
>
> Regards,
>
> Mike
>
Author
18 Jul 2006 7:22 PM
msnews.microsoft.com
ThanksDominick,

This looks like C rather than vb I will see if can work out the VB
equivelents.

I am still learning the dotnet framework so, it might take me a while, will
post back if I can't work it out.

Regards,
Michael.

Show quoteHide quote
"Dominick Baier" <dbaier@pleasepleasenospam_leastprivilege.com> wrote in
message news:4580be6356ea8c878a30b1ae24b@news.microsoft.com...
> foreach (FileSystemAccessRule rule in security.GetAccessRules(true, true,
> typeof(NTAccount)))
>            {
>                Console.WriteLine("{0} {1} access to {2}",
>                    rule.AccessControlType == AccessControlType.Allow ?
>                        "grant: " : "deny: ",
>                    rule.FileSystemRights,
>                    rule.IdentityReference.ToString());
>                SecurityIdentifier sid =
> (SecurityIdentifier)rule.IdentityReference.Translate(typeof(SecurityIdentifier));
>                Console.WriteLine(sid.Value);
>            }
>
>
>> HI all,
>>
>> How do I go about getting the permmisions of a file.
>>
>> I have been able to get a list of access control rules and tell if
>> they are restricting or permiting a permmision but I cant tell which
>> role / right they are refering to:
>>
>> I can get this type information by using the fileSystemSecurity object
>> and
>> pointing it to a file or folder:
>> ---------------------------------
>> Administrator, allow, inhertited
>> Users, allow, inhereted
>> ----------------------------------
>> But what I am aiming for is
>>
>> ---------------------------------
>> Administrator, allow Full Control, inhertited
>> Users, allow, read + Modify, inhereted
>> ----------------------------------
>> I have looked through the classes in the security name space but I am
>> not sure which class I  need to do this or if the class I am using
>> will work.
>>
>> Any help would be very welcome or even any external refrences.
>>
>> By the way I am using VB.Net and the 2.0 framework.
>>
>> Regards,
>>
>> Mike
>>
>
>
Author
18 Jul 2006 7:36 PM
msnews.microsoft.com
Hey Thanks agian Dominick,

  rule.IdentityReference.ToString());

This was the bit I needed, I could get the account Name and if it was a
Grant or Deny, but did not see how to get the type of rule it was refering
to.

Michael.


Show quoteHide quote
"msnews.microsoft.com" <m***@spike.com> wrote in message
news:ues6B%23pqGHA.644@TK2MSFTNGP05.phx.gbl...
> ThanksDominick,
>
> This looks like C rather than vb I will see if can work out the VB
> equivelents.
>
> I am still learning the dotnet framework so, it might take me a while,
> will post back if I can't work it out.
>
> Regards,
> Michael.
>
> "Dominick Baier" <dbaier@pleasepleasenospam_leastprivilege.com> wrote in
> message news:4580be6356ea8c878a30b1ae24b@news.microsoft.com...
>> foreach (FileSystemAccessRule rule in security.GetAccessRules(true, true,
>> typeof(NTAccount)))
>>            {
>>                Console.WriteLine("{0} {1} access to {2}",
>>                    rule.AccessControlType == AccessControlType.Allow ?
>>                        "grant: " : "deny: ",
>>                    rule.FileSystemRights,
>>                    rule.IdentityReference.ToString());
>>                SecurityIdentifier sid =
>> (SecurityIdentifier)rule.IdentityReference.Translate(typeof(SecurityIdentifier));
>>                Console.WriteLine(sid.Value);
>>            }
>>
>>
>>> HI all,
>>>
>>> How do I go about getting the permmisions of a file.
>>>
>>> I have been able to get a list of access control rules and tell if
>>> they are restricting or permiting a permmision but I cant tell which
>>> role / right they are refering to:
>>>
>>> I can get this type information by using the fileSystemSecurity object
>>> and
>>> pointing it to a file or folder:
>>> ---------------------------------
>>> Administrator, allow, inhertited
>>> Users, allow, inhereted
>>> ----------------------------------
>>> But what I am aiming for is
>>>
>>> ---------------------------------
>>> Administrator, allow Full Control, inhertited
>>> Users, allow, read + Modify, inhereted
>>> ----------------------------------
>>> I have looked through the classes in the security name space but I am
>>> not sure which class I  need to do this or if the class I am using
>>> will work.
>>>
>>> Any help would be very welcome or even any external refrences.
>>>
>>> By the way I am using VB.Net and the 2.0 framework.
>>>
>>> Regards,
>>>
>>> Mike
>>>
>>
>>
>
>