I'm using ActiveState Perl on Windows Server 2003.
I want to create a directory on a Windows NTFS partition and then grant a Windows NT security group read access to the folder. Is this possible in Perl? Would I have to use Windows NT commands or is there a Perl module to do it?
A small example would be much appreciated!
Modify: Allows users to read and write of files and subfolders; also allows deletion of the folder.
In Windows Explorer, right-click the folder you want to share, and then click Properties. On the Sharing tab, click Advanced Sharing. In User Account Control, click Continue to accept the prompt that Windows needs your permission to perform the action. In the Advanced Sharing dialog box, check Share this folder.
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
will overwrite the permissions for that directory. If you want to edit the existing permissions, you'd need to Get
them first:
my %permissions;
Win32::FileSecurity::Get($dir, \%permissions);
$permissions{'Power Users'}
= MakeMask( qw( READ GENERIC_READ GENERIC_EXECUTE ) ) });
Win32::FileSecurity::Set($dir, \%permissions);
Here's a generic permissions package 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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With