Visual Basic (Declaration) | |
---|---|
Public Shared Sub ReplacePermissions( _ ByVal filepath As String, _ ByVal sidType As WellKnownSidType, _ ByVal allow As FileSystemRights _ ) |
C# | |
---|---|
public static void ReplacePermissions( string filepath, WellKnownSidType sidType, FileSystemRights allow ) |
Parameters
- filepath
- sidType
- allow
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