EDN Admin
Well-known member
Hi,<br/><br/>I want to retreive the "Access List" of specified folder on remote Machine.<br/>I have the code to list all the shared folders on all the computers in the network.<br/>But I want to display only those shared folders for which the logged-in user has permissions to access.<br/><br/>I have tried the following code<br/><br/><span style="font-size:x-small;color:#008080 <font size=2 color="#008080
DirectoryInfo
</font>
<span style="font-size:x-small dInfo = <span style="font-size:x-small;color:#0000ff new<span style="font-size:x-small <span style="font-size:x-small;color:#008080 DirectoryInfo<span style="font-size:x-small;color:#008000 (@<a>\10.6.101.0SHARE7 );<br/><span style="font-size:x-small;color:#008080 <br/>DirectorySecurity<span style="font-size:x-small dSecurity = dInfo.GetAccessControl();<font size=2>
</font>
<span style="font-size:x-small;color:#008080 AuthorizationRuleCollection<span style="font-size:x-small rules = dSecurity.GetAccessRules(<span style="font-size:x-small;color:#0000ff true<span style="font-size:x-small , <span style="font-size:x-small;color:#0000ff true<span style="font-size:x-small , <span style="font-size:x-small;color:#0000ff typeof<span style="font-size:x-small (<span style="font-size:x-small;color:#008080 SecurityIdentifier<span style="font-size:x-small ));
<font size=2>
</font>
<span style="font-size:x-small;color:#008000 foreach (FileSystemAccessRule ar in rules)
<span style="font-size:x-small <font size=2>
</font>
<span style="font-size:x-small;color:#008000 {
<span style="font-size:x-small <font size=2>
</font>
<span style="font-size:x-small;color:#008000 // rights += (ar.IdentityReference as SecurityIdentifier).Value;
<span style="font-size:x-small <font size=2>
</font>
<span style="font-size:x-small;color:#008000 if (secId.CompareTo(ar.IdentityReference as SecurityIdentifier) == 0)
<span style="font-size:x-small <font size=2>
</font>
<span style="font-size:x-small;color:#008000 rights += ar.FileSystemRights.ToString();
<span style="font-size:x-small <font size=2>
</font>
<span style="font-size:x-small;color:#008000 }<br/><br/>But I am getting the following error:<br/><br/>"Exception Method failed with unexpected error code 87. at System.Security.Ac<br/>cessControl.NativeObjectSecurity.CreateInternal(ResourceType resourceType, Boole<br/>an isContainer, String name, SafeHandle handle, AccessControlSections includeSec<br/>tions, Boolean createByName, ExceptionFromErrorCode exceptionFromErrorCode, Obje<br/>ct exceptionContext)<br/> at System.Security.AccessControl.FileSystemSecurity..ctor(Boolean isContainer<br/>, String name, AccessControlSections includeSections, Boolean isDirectory)<br/> at System.Security.AccessControl.DirectorySecurity..ctor(String name, AccessC<br/>ontrolSections includeSections)<br/> at System.IO.DirectoryInfo.GetAccessControl()"<br/><br/>Can anyone help me please?<br/><br/>Regards,<br/>Anu<br/>
View the full article
DirectoryInfo
</font>
<span style="font-size:x-small dInfo = <span style="font-size:x-small;color:#0000ff new<span style="font-size:x-small <span style="font-size:x-small;color:#008080 DirectoryInfo<span style="font-size:x-small;color:#008000 (@<a>\10.6.101.0SHARE7 );<br/><span style="font-size:x-small;color:#008080 <br/>DirectorySecurity<span style="font-size:x-small dSecurity = dInfo.GetAccessControl();<font size=2>
</font>
<span style="font-size:x-small;color:#008080 AuthorizationRuleCollection<span style="font-size:x-small rules = dSecurity.GetAccessRules(<span style="font-size:x-small;color:#0000ff true<span style="font-size:x-small , <span style="font-size:x-small;color:#0000ff true<span style="font-size:x-small , <span style="font-size:x-small;color:#0000ff typeof<span style="font-size:x-small (<span style="font-size:x-small;color:#008080 SecurityIdentifier<span style="font-size:x-small ));
<font size=2>
</font>
<span style="font-size:x-small;color:#008000 foreach (FileSystemAccessRule ar in rules)
<span style="font-size:x-small <font size=2>
</font>
<span style="font-size:x-small;color:#008000 {
<span style="font-size:x-small <font size=2>
</font>
<span style="font-size:x-small;color:#008000 // rights += (ar.IdentityReference as SecurityIdentifier).Value;
<span style="font-size:x-small <font size=2>
</font>
<span style="font-size:x-small;color:#008000 if (secId.CompareTo(ar.IdentityReference as SecurityIdentifier) == 0)
<span style="font-size:x-small <font size=2>
</font>
<span style="font-size:x-small;color:#008000 rights += ar.FileSystemRights.ToString();
<span style="font-size:x-small <font size=2>
</font>
<span style="font-size:x-small;color:#008000 }<br/><br/>But I am getting the following error:<br/><br/>"Exception Method failed with unexpected error code 87. at System.Security.Ac<br/>cessControl.NativeObjectSecurity.CreateInternal(ResourceType resourceType, Boole<br/>an isContainer, String name, SafeHandle handle, AccessControlSections includeSec<br/>tions, Boolean createByName, ExceptionFromErrorCode exceptionFromErrorCode, Obje<br/>ct exceptionContext)<br/> at System.Security.AccessControl.FileSystemSecurity..ctor(Boolean isContainer<br/>, String name, AccessControlSections includeSections, Boolean isDirectory)<br/> at System.Security.AccessControl.DirectorySecurity..ctor(String name, AccessC<br/>ontrolSections includeSections)<br/> at System.IO.DirectoryInfo.GetAccessControl()"<br/><br/>Can anyone help me please?<br/><br/>Regards,<br/>Anu<br/>
View the full article