Enumerate file permissions<p><font face="Tahoma,Helvetica,Sans-Serif" size=2>Hello,</font></p> <p><font face="Tahoma,Helvetica,Sans-Serif" size=2>First, I hope that I wrote my question in the right forum... If not, sorry by advance. <img src="images/emoticons/smile_embaressed.gif"> </font></p> <p><font face="Tahoma,Helvetica,Sans-Serif" size=2>Well, I am searching for a way to list all members autorized to access a specific file or folder on the network. The application to create will have to be available for any user : meaning, for the moment, that I cannot use any admin account.</font></p> <p><font face="Tahoma,Helvetica,Sans-Serif" size=2>My question is : do you know if such application can be developped in .Net ? C# ?</font></p> <p><font face="Tahoma,Helvetica,Sans-Serif" size=2>If yes, could you please help me by indicating me the classes to use ? (I am not expert in this language, but I think that I can try to do something !) <img src="images/emoticons/smile_regular.gif"></font></p> <p><font face="Tahoma,Helvetica,Sans-Serif" size=2>Thank you by advance.</font></p> <p><font face="Tahoma,Helvetica,Sans-Serif" size=2>Sei.</font></p>© 2009 Microsoft Corporation. All rights reserved.Thu, 19 Jun 2008 00:15:52 Z60b59833-8da4-43b2-ac8c-95e87772431fhttp://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/60b59833-8da4-43b2-ac8c-95e87772431f#60b59833-8da4-43b2-ac8c-95e87772431fhttp://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/60b59833-8da4-43b2-ac8c-95e87772431f#60b59833-8da4-43b2-ac8c-95e87772431fSei_http://social.msdn.microsoft.com/Profile/en-US/?user=Sei_Enumerate file permissions<p><font face="Tahoma,Helvetica,Sans-Serif" size=2>Hello,</font></p> <p><font face="Tahoma,Helvetica,Sans-Serif" size=2>First, I hope that I wrote my question in the right forum... If not, sorry by advance. <img src="images/emoticons/smile_embaressed.gif"> </font></p> <p><font face="Tahoma,Helvetica,Sans-Serif" size=2>Well, I am searching for a way to list all members autorized to access a specific file or folder on the network. The application to create will have to be available for any user : meaning, for the moment, that I cannot use any admin account.</font></p> <p><font face="Tahoma,Helvetica,Sans-Serif" size=2>My question is : do you know if such application can be developped in .Net ? C# ?</font></p> <p><font face="Tahoma,Helvetica,Sans-Serif" size=2>If yes, could you please help me by indicating me the classes to use ? (I am not expert in this language, but I think that I can try to do something !) <img src="images/emoticons/smile_regular.gif"></font></p> <p><font face="Tahoma,Helvetica,Sans-Serif" size=2>Thank you by advance.</font></p> <p><font face="Tahoma,Helvetica,Sans-Serif" size=2>Sei.</font></p>Wed, 10 Jan 2007 11:37:28 Z2007-01-11T07:33:22Zhttp://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/60b59833-8da4-43b2-ac8c-95e87772431f#7d52bb48-c3b1-419e-8e29-3d77ea55b724http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/60b59833-8da4-43b2-ac8c-95e87772431f#7d52bb48-c3b1-419e-8e29-3d77ea55b724TaylorMichaelLhttp://social.msdn.microsoft.com/Profile/en-US/?user=TaylorMichaelLEnumerate file permissions<p>As of v2 you can use the security subsystem to enumerate the access rights of any securable object.  Firstly you'll need to get the file access rules.  Then  you can enumerate through them.  Here's some sample code that dumps the access rights of a file (folders work the same way but with different classes)<br><br><font color="#0000ff" size=2>static</font><font size=2> </font><font color="#0000ff" size=2>void</font><font size=2> Main ( </font><font color="#0000ff" size=2>string</font><font size=2>[] args )<br>{<br>   </font><font color="#2b91af" size=2>FileSecurity</font><font size=2> sec = </font><font color="#2b91af" size=2>File</font><font size=2>.GetAccessControl(</font><font color="#008000" size=2>@&quot;c:\temp&quot;</font><font size=2>);<br><br>   </font><font color="#2b91af" size=2>AuthorizationRuleCollection</font><font size=2> rules = sec.GetAccessRules(</font><font color="#0000ff" size=2>true</font><font size=2>, </font><font color="#0000ff" size=2>true</font><font size=2>, </font><font color="#0000ff" size=2>typeof</font><font size=2>(</font><font color="#2b91af" size=2>SecurityIdentifier</font><font size=2>));<br>   </font><font color="#0000ff" size=2>foreach</font><font size=2> (</font><font color="#2b91af" size=2>FileSystemAccessRule</font><font size=2> rule </font><font color="#0000ff" size=2>in</font><font size=2> rules)<br>   { <br>      </font><font color="#2b91af" size=2>NTAccount</font><font size=2> account = rule.IdentityReference.Translate(</font><font color="#0000ff" size=2>typeof</font><font size=2>(</font><font color="#2b91af" size=2>NTAccount</font><font size=2>)) </font><font color="#0000ff" size=2>as</font><font size=2> </font><font color="#2b91af" size=2>NTAccount</font><font size=2>;<br>      </font><font color="#2b91af" size=2>Console</font><font size=2>.Write(</font><font color="#008000" size=2>&quot;{0}: &quot;</font><font size=2>, account.Value);<br><br>      </font><font color="#0000ff" size=2>if</font><font size=2> (rule.AccessControlType == </font><font color="#2b91af" size=2>AccessControlType</font><font size=2>.Deny)<br>         </font><font color="#2b91af" size=2>Console</font><font size=2>.Write(</font><font color="#008000" size=2>&quot;Denied &quot;</font><font size=2>);<br>      </font><font color="#2b91af" size=2>Console</font><font size=2>.Write(</font><font color="#008000" size=2>&quot;{0}&quot;</font><font size=2>, rule.FileSystemRights);<br><br>      </font><font color="#0000ff" size=2>if</font><font size=2> (rule.IsInherited)<br>         </font><font color="#2b91af" size=2>Console</font><font size=2>.WriteLine(</font><font color="#008000" size=2>&quot; (Inherited)&quot;</font><font size=2>);<br>      </font><font color="#0000ff" size=2>else<br>         </font><font color="#2b91af" size=2>Console</font><font size=2>.WriteLine(</font><font color="#008000" size=2>&quot; (Explicit)&quot;</font><font size=2>);<br>   };<br>}</p></font> <p><font face=Verdana>Michael Taylor - 1/10/07<br><a title="http://p3net.mvps.org" href="http://p3net.mvps.org">http://p3net.mvps.org</a></font></p> <p> </p>Wed, 10 Jan 2007 16:59:08 Z2007-01-11T07:33:22Zhttp://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/60b59833-8da4-43b2-ac8c-95e87772431f#33709502-3f23-4d1a-a8a0-89677620bb68http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/60b59833-8da4-43b2-ac8c-95e87772431f#33709502-3f23-4d1a-a8a0-89677620bb68it68http://social.msdn.microsoft.com/Profile/en-US/?user=it68Enumerate file permissions<p><span style="font-size:10pt;font-family:Arial">This example does not cover situation when &quot;<strong><span style="font-family:Arial">rule.IdentityReference.Translate(<span style="color:blue">typeof</span>(<span style="color:#2b91af">NTAccount</span>)) <span style="color:blue">as</span> <span style="color:#2b91af">NTAccount</span></span></strong><span style="color:#2b91af">&quot; </span><span style="color:black">throws an exception because SID can not be translated to NTAccount. This situation is very common when file share is exposed by a system that is not part of NT domain and uses CIFS or other type of file sharing.</span></span></p> <p><span style="font-size:10pt;font-family:Arial"> </span></p> <p><span style="font-size:10pt;font-family:Arial">I found no ways so far to query if current application will have particular <span style="color:#2b91af">FileSystemRights </span><span style="color:black">permission on specific file.</span></span></p> <p><span style="font-size:10pt;font-family:Arial"> </span></p> <p><span style="font-size:10pt;color:black;font-family:Arial">Is it achievable in C#?</span><span style="font-size:10pt;font-family:Arial"></span></p> <p><font color="#2b91af" size=2></font> </p> <p align=left><font color="#2b91af" size=2>Igor Touzov 11/16/2007</p></font><font size=2> <p align=left><br></p></font> <p align=left><font face=Arial size=2></font> </p>Fri, 16 Nov 2007 17:26:24 Z2007-11-16T17:26:24Z