Visual Basic (Declaration) | |
---|---|
Public Shared Function GetPermissions( _ ByVal filepath As String, _ ByVal sidType As WellKnownSidType _ ) As FileSystemRights |
C# | |
---|---|
public static FileSystemRights GetPermissions( string filepath, WellKnownSidType sidType ) |
Parameters
- filepath
- sidType
Library/Library.Test/TestFileUtils.cs
C# | Copy Code |
---|---|
string tempFile = Path.GetTempFileName(); FileSystemRights rights; try { FileUtils.ReplacePermissions(tempFile, WellKnownSidType.WorldSid, FileSystemRights.Read); rights = FileUtils.GetPermissions(tempFile, WellKnownSidType.WorldSid); Assert.AreEqual(FileSystemRights.Read, FileSystemRights.Read & rights); FileUtils.ReplacePermissions(tempFile, WellKnownSidType.WorldSid, 0); rights = FileUtils.GetPermissions(tempFile, WellKnownSidType.WorldSid); Assert.AreEqual(0, (int)rights); FileUtils.GrantFullControlForFile(tempFile, WellKnownSidType.WorldSid); rights = FileUtils.GetPermissions(tempFile, WellKnownSidType.WorldSid); Assert.AreEqual(FileSystemRights.FullControl, rights); FileUtils.ReplacePermissions(tempFile, WellKnownSidType.WorldSid, FileSystemRights.Read); rights = FileUtils.GetPermissions(tempFile, WellKnownSidType.WorldSid); Assert.AreEqual(FileSystemRights.Read, FileSystemRights.Read & rights); FileUtils.GrantFullControlForFile(tempFile, WellKnownSidType.WorldSid); rights = FileUtils.GetPermissions(tempFile, WellKnownSidType.WorldSid); Assert.AreEqual(FileSystemRights.FullControl, rights); FileUtils.ReplacePermissions(tempFile, WellKnownSidType.WorldSid, 0); rights = FileUtils.GetPermissions(tempFile, WellKnownSidType.WorldSid); Assert.AreEqual(0, (int)rights); } finally { File.Delete(tempFile); } |
VB.NET | Copy Code |
---|---|
Dim tempFile As String = Path.GetTempFileName() Dim rights As FileSystemRights Try FileUtils.ReplacePermissions(tempFile, WellKnownSidType.WorldSid, FileSystemRights.Read) rights = FileUtils.GetPermissions(tempFile, WellKnownSidType.WorldSid) Assert.AreEqual(FileSystemRights.Read, FileSystemRights.Read And rights) FileUtils.ReplacePermissions(tempFile, WellKnownSidType.WorldSid, 0) rights = FileUtils.GetPermissions(tempFile, WellKnownSidType.WorldSid) Assert.AreEqual(0, DirectCast(rights, Integer)) FileUtils.GrantFullControlForFile(tempFile, WellKnownSidType.WorldSid) rights = FileUtils.GetPermissions(tempFile, WellKnownSidType.WorldSid) Assert.AreEqual(FileSystemRights.FullControl, rights) FileUtils.ReplacePermissions(tempFile, WellKnownSidType.WorldSid, FileSystemRights.Read) rights = FileUtils.GetPermissions(tempFile, WellKnownSidType.WorldSid) Assert.AreEqual(FileSystemRights.Read, FileSystemRights.Read And rights) FileUtils.GrantFullControlForFile(tempFile, WellKnownSidType.WorldSid) rights = FileUtils.GetPermissions(tempFile, WellKnownSidType.WorldSid) Assert.AreEqual(FileSystemRights.FullControl, rights) FileUtils.ReplacePermissions(tempFile, WellKnownSidType.WorldSid, 0) rights = FileUtils.GetPermissions(tempFile, WellKnownSidType.WorldSid) Assert.AreEqual(0, DirectCast(rights, Integer)) Finally File.Delete(tempFile) End Try |
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7