How can I change Windows NTFS permissions to Perl?

I am using ActiveState Perl on Windows Server 2003.

I want to create a directory on a Windows NTFS partition, and then grant access to the security folder of the Windows NT security group. Is this possible in Perl? Should I use Windows NT commands or is there a Perl module for this?

A small example will be greatly appreciated!

+4
source share
2 answers

The standard way is to use the Win32 :: FileSecurity module :

use Win32::FileSecurity qw(Set MakeMask); my $dir = 'c:/newdir'; mkdir $dir or die $!; Set($dir, { 'Power Users' => MakeMask( qw( READ GENERIC_READ GENERIC_EXECUTE ) ) }); 

Note that Set overwrite permissions for this directory. If you want to edit existing permissions, you first need to Get them:

 my %permissions; Win32::FileSecurity::Get($dir, \%permissions); $permissions{'Power Users'} = MakeMask( qw( READ GENERIC_READ GENERIC_EXECUTE ) ) }); Win32::FileSecurity::Set($dir, \%permissions); 
+9
source

Here's a generic permission pack for ActivePerl.

 use Win32::Perms; # Create a new Security Descriptor and auto import permissions # from the directory $Dir = new Win32::Perms( 'c:/temp' ) || die; # One of three ways to remove an ACE $Dir->Remove('guest'); # Deny access for all attributes (deny read, deny write, etc) $Dir->Deny( 'joel', FULL ); # Set the directory permissions (no need to specify the # path since the object was created with it) $Dir->Set(); # If you are curious about the contents of the SD # dump the contents to STDOUT $Dir->Dump; 
+6
source

All Articles